This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[v3] speedup numpunct cache a bit
- From: Jerry Quinn <jlquinn at optonline dot net>
- To: libstdc++ at gcc dot gnu dot org
- Date: Fri, 27 Jun 2003 22:38:02 -0400
- Subject: [v3] speedup numpunct cache a bit
This moves the code for __use_cache<numpunct> to locale_facets.tcc.
It shaves about 2% off testsuite/performance/ofstream_insert_float.cc
from 4.15s down to 4.0s. gcc 2.95 gives 3.6s at -O2, so we're getting
closer.
Jerry
2003-06-27 Jerry Quinn <jlquinn@optonline.net>
* src/locale.cc (__use_cache<numpunct>): Move from here ...
* include/bits/locale_facets.tcc (__use_cache<numpunct>): To
here.
Index: include/bits/locale_facets.tcc
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/bits/locale_facets.tcc,v
retrieving revision 1.100
diff -u -r1.100 locale_facets.tcc
--- include/bits/locale_facets.tcc 27 Jun 2003 07:25:37 -0000 1.100
+++ include/bits/locale_facets.tcc 28 Jun 2003 02:29:40 -0000
@@ -93,13 +93,35 @@
__use_cache(const locale& __loc);
template<>
- const __numpunct_cache<char>&
- __use_cache(const locale& __loc);
+ inline const __numpunct_cache<char>&
+ __use_cache(const locale& __loc)
+ {
+ size_t __i = numpunct<char>::id._M_id();
+ const locale::facet** __caches = __loc._M_impl->_M_caches;
+ if (!__caches[__i])
+ {
+ __numpunct_cache<char>* __tmp = new __numpunct_cache<char>;
+ __tmp->_M_cache(__loc);
+ __loc._M_impl->_M_install_cache(__tmp, __i);
+ }
+ return static_cast<const __numpunct_cache<char>&>(*__caches[__i]);
+ }
#ifdef _GLIBCPP_USE_WCHAR_T
template<>
- const __numpunct_cache<wchar_t>&
- __use_cache(const locale& __loc);
+ inline const __numpunct_cache<wchar_t>&
+ __use_cache(const locale& __loc)
+ {
+ size_t __i = numpunct<wchar_t>::id._M_id();
+ const locale::facet** __caches = __loc._M_impl->_M_caches;
+ if (!__caches[__i])
+ {
+ __numpunct_cache<wchar_t>* __tmp = new __numpunct_cache<wchar_t>;
+ __tmp->_M_cache(__loc);
+ __loc._M_impl->_M_install_cache(__tmp, __i);
+ }
+ return static_cast<const __numpunct_cache<wchar_t>&>(*__caches[__i]);
+ }
#endif
// Stage 1: Determine a conversion specifier.
Index: src/locale.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/src/locale.cc,v
retrieving revision 1.83
diff -u -r1.83 locale.cc
--- src/locale.cc 27 Jun 2003 07:25:37 -0000 1.83
+++ src/locale.cc 28 Jun 2003 02:29:40 -0000
@@ -449,38 +449,6 @@
locale::facet::
~facet() { }
- template<>
- const __numpunct_cache<char>&
- __use_cache(const locale& __loc)
- {
- size_t __i = numpunct<char>::id._M_id();
- const locale::facet** __caches = __loc._M_impl->_M_caches;
- if (!__caches[__i])
- {
- __numpunct_cache<char>* __tmp = new __numpunct_cache<char>;
- __tmp->_M_cache(__loc);
- __loc._M_impl->_M_install_cache(__tmp, __i);
- }
- return static_cast<const __numpunct_cache<char>&>(*__caches[__i]);
- }
-
-#ifdef _GLIBCPP_USE_WCHAR_T
- template<>
- const __numpunct_cache<wchar_t>&
- __use_cache(const locale& __loc)
- {
- size_t __i = numpunct<wchar_t>::id._M_id();
- const locale::facet** __caches = __loc._M_impl->_M_caches;
- if (!__caches[__i])
- {
- __numpunct_cache<wchar_t>* __tmp = new __numpunct_cache<wchar_t>;
- __tmp->_M_cache(__loc);
- __loc._M_impl->_M_install_cache(__tmp, __i);
- }
- return static_cast<const __numpunct_cache<wchar_t>&>(*__caches[__i]);
- }
-#endif
-
// Definitions for static const data members of time_base
template<>
const char*