[Patch] Fix libstdc++/13341 (speed-up <wchar_t>::do_narrow/widen)
Benjamin Kosnik
bkoz@redhat.com
Fri Dec 12 06:30:00 GMT 2003
Hmmm. Just a thought: instead of storing an array of int, why don't you
just store an array of char, and don't cache at all if you run into an
error when constructing the cache? Then:
ctype<wchar_t>::
do_narrow(wchar_t __wc, char __dfault) const
{
! int __c;
! if (__wc >= 0 && __wc < 128)
! __c = _M_narrow[__wc];
! else
! __c = wctob(__wc);
return (__c == EOF ? __dfault : static_cast<char>(__c));
}
Would become something like
ctype<wchar_t>::
do_narrow(wchar_t __wc, char __dfault) const
{
if (cached and range ok)
return _M_narrow[__wc]; // know this is an a-ok char
else
{
int __c = wctob(__wc);
return (__c == EOF ? __dfault : static_cast<char>(__c));
}
best,
benjamin
More information about the Libstdc++
mailing list