ctype_noninline.h, [...] (ctype): Initialize _M_narrow, _M_widen.
authorJerry Quinn <jlquinn@optonline.net>
Tue, 16 Dec 2003 01:57:03 +0000 (01:57 +0000)
committerJerry Quinn <jlquinn@gcc.gnu.org>
Tue, 16 Dec 2003 01:57:03 +0000 (01:57 +0000)
2003-12-15  Jerry Quinn  <jlquinn@optonline.net>

        * config/os/aix/ctype_noninline.h,
config/os/bsd/freebsd/ctype_noninline.h,
config/os/bsd/netbsd/ctype_noninline.h,
config/os/djgpp/ctype_noninline.h,
config/os/generic/ctype_noninline.h,
config/os/gnu-linux/ctype_noninline.h,
config/os/hpux/ctype_noninline.h,
config/os/irix/irix5.2/ctype_noninline.h,
config/os/irix/irix6.5/ctype_noninline.h,
config/os/mingw32/ctype_noninline.h,
config/os/newlib/ctype_noninline.h,
config/os/qnx/qnx6.1/ctype_noninline.h,
config/os/solaris/solaris2.5/ctype_noninline.h,
config/os/solaris/solaris2.6/ctype_noninline.h,
config/os/solaris/solaris2.7/ctype_noninline.h,
config/os/vxworks/ctype_noninline.h,
config/os/windiss/ctype_noninline.h (ctype):  Initialize
_M_narrow, _M_widen.
* include/bits/locale_facets.h (_M_widen, _M_widen_ok,
_M_narrow, _M_narrow_ok): New.
(widen, narrow): Use tables to bypass virtual functions.
(_M_widen_init, _M_narrow_init): New.

From-SVN: r74662

20 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/config/os/aix/ctype_noninline.h
libstdc++-v3/config/os/bsd/freebsd/ctype_noninline.h
libstdc++-v3/config/os/bsd/netbsd/ctype_noninline.h
libstdc++-v3/config/os/djgpp/ctype_noninline.h
libstdc++-v3/config/os/generic/ctype_noninline.h
libstdc++-v3/config/os/gnu-linux/ctype_noninline.h
libstdc++-v3/config/os/hpux/ctype_noninline.h
libstdc++-v3/config/os/irix/irix5.2/ctype_noninline.h
libstdc++-v3/config/os/irix/irix6.5/ctype_noninline.h
libstdc++-v3/config/os/mingw32/ctype_noninline.h
libstdc++-v3/config/os/newlib/ctype_noninline.h
libstdc++-v3/config/os/qnx/qnx6.1/ctype_noninline.h
libstdc++-v3/config/os/solaris/solaris2.5/ctype_noninline.h
libstdc++-v3/config/os/solaris/solaris2.6/ctype_noninline.h
libstdc++-v3/config/os/solaris/solaris2.7/ctype_noninline.h
libstdc++-v3/config/os/vxworks/ctype_noninline.h
libstdc++-v3/config/os/windiss/ctype_noninline.h
libstdc++-v3/include/bits/locale_facets.h
libstdc++-v3/testsuite/performance/narrow_widen_char.cc [new file with mode: 0644]

index 5e560e0bc98047553e1a748ad94e602bcc1810c6..853f86afca51c55394ee1b594ad43f96f08b1e73 100644 (file)
@@ -1,3 +1,28 @@
+2003-12-15  Jerry Quinn  <jlquinn@optonline.net>
+
+        * config/os/aix/ctype_noninline.h,
+       config/os/bsd/freebsd/ctype_noninline.h,
+       config/os/bsd/netbsd/ctype_noninline.h,
+       config/os/djgpp/ctype_noninline.h,
+       config/os/generic/ctype_noninline.h,
+       config/os/gnu-linux/ctype_noninline.h,
+       config/os/hpux/ctype_noninline.h,
+       config/os/irix/irix5.2/ctype_noninline.h,
+       config/os/irix/irix6.5/ctype_noninline.h,
+       config/os/mingw32/ctype_noninline.h,
+       config/os/newlib/ctype_noninline.h,
+       config/os/qnx/qnx6.1/ctype_noninline.h,
+       config/os/solaris/solaris2.5/ctype_noninline.h,
+       config/os/solaris/solaris2.6/ctype_noninline.h,
+       config/os/solaris/solaris2.7/ctype_noninline.h,
+       config/os/vxworks/ctype_noninline.h,
+       config/os/windiss/ctype_noninline.h (ctype):  Initialize
+       _M_narrow, _M_widen.
+       * include/bits/locale_facets.h (_M_widen, _M_widen_ok,
+       _M_narrow, _M_narrow_ok): New.
+       (widen, narrow): Use tables to bypass virtual functions.
+       (_M_widen_init, _M_narrow_init): New.
+
 2003-12-15  Carlo Wood  <carlo@alinoe.com>
 
        * include/bits/ios_base.h (Init::_S_initialized): Change into
index 78fce2ef176a17b7f715698c005efe43c4477b60..edd8d82f3f6176ce4829478ea354e53d3f218d3c 100644 (file)
   : facet(__refs), _M_del(__table != 0 && __del),
   _M_toupper(NULL), _M_tolower(NULL),
   _M_table(__table ? __table : classic_table())
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
   : facet(__refs), _M_del(__table != 0 && __del),
   _M_toupper(NULL), _M_tolower(NULL),
   _M_table(__table ? __table : classic_table())
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index 27cd28c082eb41bc20b66f91a2af881a36a64b83..ec5b5753547ac2afcbfbbb12970fed7a9577554a 100644 (file)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table ? __table : classic_table()) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) 
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table ? __table : classic_table()) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index 0cc08aef248de497e6ac2fc9b4b4f09d9eaa4e91..70bf41c22e10427ebe1878656a7f1ac5432519c0 100644 (file)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table ? __table : classic_table())
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) 
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table ? __table : classic_table())
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index 848f5e2bde7806f88c4a6bf71224ad73ad48d212..eda2679ed3c15a217baffdb1f9d8a2a5e72e421f 100644 (file)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(__dj_ctype_toupper), _M_tolower(__dj_ctype_tolower),
   _M_table(__table ? __table : __dj_ctype_flags)  
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) 
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(__dj_ctype_toupper), _M_tolower(__dj_ctype_tolower),
   _M_table(__table ? __table : __dj_ctype_flags)  
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index 92e1173ed6721baae4f74fc1e75344412176d2c7..e30348e605807bb76a0f7c2c05cd128caa77df90 100644 (file)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table ? __table : classic_table()) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) 
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table ? __table : classic_table())
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index 8d38627f7bdf4e17b64c2b3ba3c85ab44c735226..ae4c14d5d589acfe6bc763950fb396896ee06168 100644 (file)
     _M_toupper = _M_c_locale_ctype->__ctype_toupper;
     _M_tolower = _M_c_locale_ctype->__ctype_tolower;
     _M_table = __table ? __table : _M_c_locale_ctype->__ctype_b;
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
   }
 #else
   ctype<char>::ctype(__c_locale, const mask* __table, bool __del, 
     setlocale(LC_CTYPE, __old);
     free(__old);
     _M_c_locale_ctype = _S_get_c_locale();
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
   }
 #endif
 
     _M_toupper = _M_c_locale_ctype->__ctype_toupper;
     _M_tolower = _M_c_locale_ctype->__ctype_tolower;
     _M_table = __table ? __table : _M_c_locale_ctype->__ctype_b;
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
   }
 #else
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
     setlocale(LC_CTYPE, __old);
     free(__old);
     _M_c_locale_ctype = _S_get_c_locale();
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
   }
 #endif
 
index c42fd8a49eeece27876b832c70de58dc221bc141..00e338b6e0645fc01a412fe5dfff80e1edfb46ff 100644 (file)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table ? __table : (const mask *) __SB_masks) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) 
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table ? __table : (const mask *) __SB_masks) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index 2268a9b9e2c2bc108f970416724aab95ef255113..2aeb50c658b138e970f42d4d3aff9815da70c0b2 100644 (file)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(!__table ? classic_table() : __table)
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(!__table ? classic_table() : __table)
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index c0e6e56d51529b5f37a5f2dd049dfd8b25a05ed5..8fdf95ef7a9f564ad5afa2430b190e985865ec46 100644 (file)
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(!__table ? 
           (const mask*) (__libc_attr._ctype_tbl->_class + 1) : __table) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(!__table ? 
           (const mask*) (__libc_attr._ctype_tbl->_class + 1) : __table) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index 4ea7b892cca774aebbc02cc6648813060f77a951..e493d403030a0f49ec79225af72b4ee47b387de3 100644 (file)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL),
   _M_table(__table ? __table : classic_table())  
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) 
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL),
   _M_table(__table ? __table : classic_table()) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index 7c5f053528a1db45cfd5b44e8106aaa98417375d..d0cce941b4c711dbd181c46c54b790379fe528c4 100644 (file)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table ? __table : classic_table()) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) 
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table ? __table : classic_table()) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index f4e2ca5f6c686e19082338169824d7482b882b5b..2eef13a7e6573b0801676de375622fb58d5d6413 100644 (file)
                     size_t __refs) 
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), _M_table(__table ? __table : _Ctype)
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) 
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), _M_table(__table ? __table : _Ctype)
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index 25eec3418b0ccf7d42b168c12b0c01ba04da4a7a..a80863653ffb41d5f3a45ff1546557f205dd92d1 100644 (file)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table ? __table : classic_table()) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) 
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table ? __table : classic_table()) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index 659c81a3ffe4b71f3a64002691f4824c3f7dce31..694901a5dc7b220957c9813d82484cbc097505bd 100644 (file)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(__trans_upper), _M_tolower(__trans_lower), 
   _M_table(__table ? __table : classic_table()) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) 
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(__trans_upper), _M_tolower(__trans_lower), 
   _M_table(__table ? __table : classic_table()) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index 81536b5fc8777d0ba2ccad439fd15ab77908f005..d4917f069cbc7b37cdf30e32850404ab831aa428 100644 (file)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(__trans_upper), _M_tolower(__trans_lower),
   _M_table(__table ? __table : classic_table()) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(__trans_upper), _M_tolower(__trans_lower),
   _M_table(__table ? __table : classic_table()) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index 4f4e92b16932626d5176c7209a17242beb551618..acf91a4aa55db061ae1bd526ff5b33220f577a46 100644 (file)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table ? __table : classic_table()) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) 
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table ? __table : classic_table())
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index a22b65d46d0bc42784bcb64c83a70408a9d01049..cf75ddfd96ca19694ae2fc6106624345a38e58a7 100644 (file)
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table == 0 ? classic_table() : __table) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) 
   : facet(__refs), _M_del(__table != 0 && __del), 
   _M_toupper(NULL), _M_tolower(NULL), 
   _M_table(__table == 0 ? classic_table() : __table) 
-  { }
+  { 
+    memset(_M_widen, 0, sizeof(_M_widen));
+    _M_widen_ok = 0;
+    memset(_M_narrow, 0, sizeof(_M_narrow));
+    _M_narrow_ok = 0;
+  }
 
   char
   ctype<char>::do_toupper(char __c) const
index 83d77c81119f8937f2b14bd4d0c8e7bf77d9e407..08cd2960e18f913edd1eb5c443cbeb894e6fd515 100644 (file)
@@ -325,6 +325,11 @@ namespace std
       __to_type                _M_toupper;
       __to_type                _M_tolower;
       const mask*                      _M_table;
+      mutable char             _M_widen_ok;
+      mutable char             _M_widen[1 + static_cast<unsigned char>(-1)];
+      mutable char             _M_narrow[1 + static_cast<unsigned char>(-1)];
+      mutable char             _M_narrow_ok;   // 0 uninitialized, 1 init,
+                                               // 2 non-consecutive
       
     public:
       static locale::id        id;
@@ -367,20 +372,46 @@ namespace std
 
       char_type 
       widen(char __c) const
-      { return this->do_widen(__c); }
+      { 
+//     if (_M_widen_ok) return _M_widen[__c];
+//     this->_M_widen_init();
+       return this->do_widen(__c);
+      }
 
       const char*
       widen(const char* __lo, const char* __hi, char_type* __to) const
-      { return this->do_widen(__lo, __hi, __to); }
+      {
+//     if (_M_widen_ok == 1)
+//       {
+//         memcpy(__to, __lo, __hi - __lo);
+//         return __hi;
+//       }
+//     if (!_M_widen_ok) _M_widen_init();
+       return this->do_widen(__lo, __hi, __to);
+      }
 
       char 
       narrow(char_type __c, char __dfault) const
-      { return this->do_narrow(__c, __dfault); }
+      {
+//     if (_M_narrow[__c]) return _M_narrow[__c];
+       char __t = do_narrow(__c, __dfault);
+//     if (__t != __dfault) _M_narrow[__c] = __t;
+       return __t;
+      }
 
       const char_type*
       narrow(const char_type* __lo, const char_type* __hi,
              char __dfault, char *__to) const
-      { return this->do_narrow(__lo, __hi, __dfault, __to); }
+      {
+//     if (__builtin_expect(_M_narrow_ok==1,true))
+//       {
+//         memcpy(__to, __lo, __hi - __lo);
+//         return __hi;
+//       }
+//     if (!_M_narrow_ok)
+//       _M_narrow_init();
+       return this->do_narrow(__lo, __hi, __dfault, __to);
+      }
 
     protected:
       const mask* 
@@ -427,6 +458,54 @@ namespace std
        memcpy(__dest, __lo, __hi - __lo);
        return __hi;
       }
+
+    private:
+
+      void _M_widen_init() const
+      {
+       char __tmp[sizeof(_M_widen)];
+       for (unsigned __i = 0; __i < sizeof(_M_widen); ++__i)
+         __tmp[__i] = __i;
+       do_widen(__tmp, __tmp + sizeof(__tmp), _M_widen);
+           
+       _M_widen_ok = 1;
+       // Set _M_widen_ok to 2 if memcpy can't be used.
+       for (unsigned __i = 0; __i < sizeof(_M_widen); ++__i)
+         if (__tmp[__i] != _M_widen[__i])
+           {
+             _M_widen_ok = 2;
+             break;
+           }
+      }
+
+      // Fill in the narrowing cache and flag whether all values are
+      // valid or not.  _M_narrow_ok is set to 1 if the whole table is
+      // narrowed, 2 if only some values could be narrowed.
+      void _M_narrow_init() const
+      {
+       char __tmp[sizeof(_M_narrow)];
+       for (unsigned i = 0; i < sizeof(_M_narrow); ++i)
+         __tmp[i] = i;
+       do_narrow(__tmp, __tmp + sizeof(__tmp), 0, _M_narrow);
+
+       // Check if any default values were created.  Do this by
+       // renarrowing with a different default value and comparing.
+       bool __consecutive = true;
+       for (unsigned __i = 0; __i < sizeof(_M_narrow); ++__i)
+         {
+           char __c[1];
+           if (!_M_narrow[__i])
+             {
+               do_narrow(__tmp + __i, __tmp + __i + 1, 1, __c);
+               if (__c[0] == 1)
+                 {
+                   __consecutive = false;
+                   break;
+                 }
+             }
+         }
+       _M_narrow_ok = __consecutive ? 1 : 2;
+      }
     };
  
   template<>
diff --git a/libstdc++-v3/testsuite/performance/narrow_widen_char.cc b/libstdc++-v3/testsuite/performance/narrow_widen_char.cc
new file mode 100644 (file)
index 0000000..d4dd658
--- /dev/null
@@ -0,0 +1,76 @@
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <locale>
+#include <testsuite_performance.h>
+
+int main()
+{
+  using namespace std;
+  using namespace __gnu_test;
+
+  time_counter time;
+  resource_counter resource;
+  const long iters = 200000000;
+  char bufin[] = "This was an attempt to bypass string construction just for test.";
+  char bufout[sizeof(bufin) + 1];
+
+  locale loc;
+  const ctype<char>& ct = use_facet<ctype<char> >(loc);
+
+  // narrow
+  start_counters(time, resource);
+  for (long i = 0; i < 1000000000; ++i)
+    ct.narrow(i % 128, '*');
+  stop_counters(time, resource);
+  report_performance(__FILE__, "narrow", time, resource);
+  clear_counters(time, resource);
+
+  // narrow array
+  start_counters(time, resource);
+  for (long i = 0; i < 100000000; ++i)
+    ct.narrow(bufin, bufin+sizeof(bufin), '*', bufout);
+  stop_counters(time, resource);
+  report_performance(__FILE__, "narrow_array", time, resource);
+  clear_counters(time, resource);
+
+  // widen
+  start_counters(time, resource);
+  for (long i = 0; i < iters; ++i)
+    ct.widen(i % 128);
+  stop_counters(time, resource);
+  report_performance(__FILE__, "widen", time, resource);
+
+  // widen array
+  start_counters(time, resource);
+  for (long i = 0; i < iters; ++i)
+    ct.widen(bufin, bufin+sizeof(bufin), bufout);
+  stop_counters(time, resource);
+  report_performance(__FILE__, "widen_array", time, resource);
+
+  return 0;
+}