This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[v3] speedup numpunct cache, take 2


Please look very carefully at this.  To make things compile, I had to
disable implicit templates when compiling concept-inst.cc.  Without
doing this, I would get duplicate symbols for numpunct<char>::id and
numpunct<wchar_t>::id during linking.  This change does pass make
check with no regressions.

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-07-03  Jerry Quinn  <jlquinn@optonline.net>

	* src/locale.cc (__use_cache<numpunct>): Move from here ...
	* include/bits/locale_facets.tcc (__use_cache<numpunct>): To
	here.
	* src/Makefile.am (concept-inst.o): Remove
	-fimplicit-templates.
	* src/Makefile.in: Regenerate.

Index: include/bits/locale_facets.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/locale_facets.tcc,v
retrieving revision 1.103
diff -u -r1.103 locale_facets.tcc
--- include/bits/locale_facets.tcc	1 Jul 2003 05:38:04 -0000	1.103
+++ include/bits/locale_facets.tcc	3 Jul 2003 04:28:32 -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/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/Makefile.am,v
retrieving revision 1.123
diff -u -r1.123 Makefile.am
--- src/Makefile.am	12 Jun 2003 03:24:16 -0000	1.123
+++ src/Makefile.am	3 Jul 2003 04:28:32 -0000
@@ -168,13 +168,13 @@
 strstream.o: strstream.cc
 	$(CXXCOMPILE) -I$(GLIBCPP_INCLUDE_DIR)/backward -Wno-deprecated -c $<
 
-# Use special rules for the concept-checking instantiations so that all
-# the generated template functions are also instantiated.  Force the checks
-# to be on so that the instantiations are actually seen.
+# Use special rules for the concept-checking instantiations to turn on
+# concept checking.  We can't implicitly instantiate here, because it
+# puts symbols into multiple files.  
 concept-inst.lo: concept-inst.cc
-	$(LTCXXCOMPILE) -D_GLIBCPP_CONCEPT_CHECKS -fimplicit-templates -c $<
+	$(LTCXXCOMPILE) -D_GLIBCPP_CONCEPT_CHECKS -c $<
 concept-inst.o: concept-inst.cc
-	$(CXXCOMPILE) -D_GLIBCPP_CONCEPT_CHECKS -fimplicit-templates -c $<
+	$(CXXCOMPILE) -D_GLIBCPP_CONCEPT_CHECKS -c $<
 
 # Use special rules for the demangler, so that an additional implicit
 # instantiation file is not necessary.
Index: src/Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/Makefile.in,v
retrieving revision 1.174
diff -u -r1.174 Makefile.in
--- src/Makefile.in	30 Jun 2003 17:40:13 -0000	1.174
+++ src/Makefile.in	3 Jul 2003 04:28:32 -0000
@@ -572,13 +572,13 @@
 strstream.o: strstream.cc
 	$(CXXCOMPILE) -I$(GLIBCPP_INCLUDE_DIR)/backward -Wno-deprecated -c $<
 
-# Use special rules for the concept-checking instantiations so that all
-# the generated template functions are also instantiated.  Force the checks
-# to be on so that the instantiations are actually seen.
+# Use special rules for the concept-checking instantiations to turn on
+# concept checking.  We can't implicitly instantiate here, because it
+# puts symbols into multiple files.  
 concept-inst.lo: concept-inst.cc
-	$(LTCXXCOMPILE) -D_GLIBCPP_CONCEPT_CHECKS -fimplicit-templates -c $<
+	$(LTCXXCOMPILE) -D_GLIBCPP_CONCEPT_CHECKS -c $<
 concept-inst.o: concept-inst.cc
-	$(CXXCOMPILE) -D_GLIBCPP_CONCEPT_CHECKS -fimplicit-templates -c $<
+	$(CXXCOMPILE) -D_GLIBCPP_CONCEPT_CHECKS -c $<
 
 # Use special rules for the demangler, so that an additional implicit
 # instantiation file is not necessary.
Index: src/locale-inst.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/locale-inst.cc,v
retrieving revision 1.39
diff -u -r1.39 locale-inst.cc
--- src/locale-inst.cc	27 Jun 2003 07:25:37 -0000	1.39
+++ src/locale-inst.cc	3 Jul 2003 04:28:32 -0000
@@ -56,7 +56,7 @@
 #endif
 
   // numpunct, numpunct_byname, num_get, and num_put
-  template class numpunct<char>;
+   template class numpunct<char>;
   template struct __numpunct_cache<char>;
   template class numpunct_byname<char>;
   template class num_get<char, istreambuf_iterator<char> >;
Index: src/locale.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/locale.cc,v
retrieving revision 1.85
diff -u -r1.85 locale.cc
--- src/locale.cc	1 Jul 2003 05:38:04 -0000	1.85
+++ src/locale.cc	3 Jul 2003 04:28:32 -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*


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