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: [v3] speedup numpunct cache, take 2


Phil Edwards writes:
 > On Thu, Jul 03, 2003 at 12:35:55AM -0400, Jerry Quinn wrote:
 > > 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
 > 
 > This strikes me as wrong, but I don't know what's up with the multiple ::id
 > instantiations.  We already have "extern template class numpunct<char>;"
 > in the .tcc file, so putting the functions in that file should be okay.
 > (I thought.)
 > 
 > I /do/ know that this will largely defeat the purpose of
 > concept-inst.cc.  Some brief discussion about why it is the way it is:
 > http://gcc.gnu.org/ml/libstdc++/2001-09/msg00026.html.  This will cause
 > problems, especially if we want concept checking on by default in 3.4
 > (mentioned as a possibility at the summit).

I was afraid of something like this.  In fact, I was surprised that it
didn't spew missing symbol warnings when I removed the implicit
instantiation flags.

As it is, we have a number of instantiation files aside fom this one.
How likely is it now that we'll get concept checking trying to find a
symbol that isn't instantiated in another file?

To my naive eye, it appears that concept-inst.cc is only checking on
stuff we had to instantiate anyway as part of the library.


 > >    // 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> >;
 > 
 > Uh?

Patch minus the turd ...

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.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]