This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Patch] Fix libstdc++/13341 (speed-up<wchar_t>::do_narrow/widen)
- From: Benjamin Kosnik <bkoz at redhat dot com>
- To: Paolo Carlini <pcarlini at suse dot de>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Fri, 12 Dec 2003 00:27:19 -0600
- Subject: Re: [Patch] Fix libstdc++/13341 (speed-up<wchar_t>::do_narrow/widen)
- Organization: Red Hat / Chicago
- References: <3FD89A30.50103@suse.de>
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