This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] Fix libstdc++/13341 (speed-up<wchar_t>::do_narrow/widen)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]