ctype_members.cc (do_is(mask, wchar_t)): Speed-up for the common case of mask ==...
authorPaolo Carlini <pcarlini@suse.de>
Mon, 18 Jul 2005 17:42:32 +0000 (17:42 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 18 Jul 2005 17:42:32 +0000 (17:42 +0000)
2005-07-18  Paolo Carlini  <pcarlini@suse.de>

* config/locale/gnu/ctype_members.cc (do_is(mask, wchar_t)):
Speed-up for the common case of mask == ctype_base::space;
otherwise, exit the loop earlier if the mask is one of the
elementary ones.

From-SVN: r102137

libstdc++-v3/ChangeLog
libstdc++-v3/config/locale/gnu/ctype_members.cc

index 15862e3772aac4c8a721fc0d9073692244ca8087..4f7b8db3831b087b09769f72e9bea13dd718fe39 100644 (file)
@@ -1,3 +1,10 @@
+2005-07-18  Paolo Carlini  <pcarlini@suse.de>
+
+       * config/locale/gnu/ctype_members.cc (do_is(mask, wchar_t)):
+       Speed-up for the common case of mask == ctype_base::space;
+       otherwise, exit the loop earlier if the mask is one of the
+       elementary ones.
+
 2005-07-14  Paolo Carlini  <pcarlini@suse.de>
 
        PR libstdc++/21193 (float, double, long double)
index fcb0551b3829db2ab73b121f6613b597940bba3c..a006929ac8e54de474a0bb8136b474a97444a5aa 100644 (file)
@@ -134,20 +134,34 @@ namespace std
   ctype<wchar_t>::
   do_is(mask __m, wchar_t __c) const
   { 
-    // Highest bitmask in ctype_base == 10, but extra in "C"
-    // library for blank.
+    // The case of __m == ctype_base::space is particularly important,
+    // due to its use in many istream functions.  Therefore we deal with
+    // it first, exploiting the knowledge that on GNU systems _M_bit[5]
+    // is the mask corresponding to ctype_base::space.  NB: an encoding
+    // change would not affect correctness!
     bool __ret = false;
-    const size_t __bitmasksize = 11; 
-    for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
-      if (__m & _M_bit[__bitcur]
-         && __iswctype_l(__c, _M_wmask[__bitcur], _M_c_locale_ctype))
-       {
-         __ret = true;
-         break;
-       }
+    if (__m == _M_bit[5])
+      __ret = __iswctype_l(__c, _M_wmask[5], _M_c_locale_ctype);
+    else
+      {
+       // Highest bitmask in ctype_base == 10, but extra in "C"
+       // library for blank.
+       const size_t __bitmasksize = 11;
+       for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
+         if (__m & _M_bit[__bitcur])
+           {
+             if (__iswctype_l(__c, _M_wmask[__bitcur], _M_c_locale_ctype))
+               {
+                 __ret = true;
+                 break;
+               }
+             else if (__m == _M_bit[__bitcur])
+               break;
+           }
+      }
     return __ret;    
   }
-  
+
   const wchar_t* 
   ctype<wchar_t>::
   do_is(const wchar_t* __lo, const wchar_t* __hi, mask* __vec) const