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]

[Patch] libstdc++/28080, fourth installment


Hi,

probably the last one for a while, I have to attend to a few different tasks...

Anyway, this is also useful, the most important ""new"" idea is including <iosfwd> instead of <ios>: as far as I can see, provided we tweak a bit templated extractors to refer to ios_base as base class, we can safely do the change, spare a lot of size and improve consistently compile time (when I/O is not needed).

A rather larger improvement is present in <complex>, and I'd like Gaby to have a look: I'm avoiding the inclusion of the whole <sstream> in that case, in favor of the tiny <iosfwd>: the preprocessed header becomes 1/3 the size! I have to tweak the extractor as per the above comment, + avoid a temporary stringstream in the inserter: in all my tests, insertion performance actually *improves*, by a factor of about 2! In my analysis, that's because we have to call the 5 individual inserters anyway and we spare the time of copying the final string to the output buffer. Note this is the case (the performance improvement, that is) both for our buffered and unbuffered streambuffer. I'm also tweaking a bit the fall-back std::abs implementation, to avoid including stl_algobase.h for the sake of one single std::max...

Tested x86-linux, without PCHs, as usual.

Paolo.

/////////////////////
2007-02-27  Paolo Carlini  <pcarlini@suse.de>

	PR libstdc++/28080 (partial)
	* include/std/complex: Do not include <sstream>, <iosfwd> is enough.
	(operator>>(std::basic_istream<>&, complex<>&)): Tweak, use ios_base
	as a base of basic_istream.
	(operator<<(std::basic_ostream<>&, const complex<>&): Do not use a
	stringstream, direct insertion isn't slower.
	(__complex_abs(const complex<>&): Avoid std::max.
	* src/complex_io.cc: Include <istream>.
	* include/std/bitset: Do not include <ios>, <iosfwd> is enough.
	(operator>>(std::basic_istream<>&, bitset<>&)): Tweak, use ios_base
	as a base of basic_istream.
	* include/std/iomanip: Do not include <ios>, <iosfwd> + 
	<bits/ios_base.h> is enough.
	* include/bits/ostream.tcc: Clean up, do not include <locale> here...
	* include/std/ostream: ... here instead.
	* include/bits/istream.tcc: Likewise for <locale> and <ostream>...
	* include/std/istream: ... here.
	* include/bits/sstream.tcc: Do not include <sstream>.
Index: src/complex_io.cc
===================================================================
--- src/complex_io.cc	(revision 122328)
+++ src/complex_io.cc	(working copy)
@@ -1,6 +1,7 @@
 // The template and inlines for the -*- C++ -*- complex number classes.
 
-// Copyright (C) 2000, 2001, 2005, 2006 Free Software Foundation, Inc.
+// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+// 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
@@ -28,6 +29,7 @@
 // the GNU General Public License.
 
 #include <complex>
+#include <istream>
 
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
Index: include/bits/istream.tcc
===================================================================
--- include/bits/istream.tcc	(revision 122328)
+++ include/bits/istream.tcc	(working copy)
@@ -43,9 +43,6 @@
 
 #pragma GCC system_header
 
-#include <locale>
-#include <ostream> // For flush()
-
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
   template<typename _CharT, typename _Traits>
Index: include/bits/ostream.tcc
===================================================================
--- include/bits/ostream.tcc	(revision 122328)
+++ include/bits/ostream.tcc	(working copy)
@@ -1,6 +1,7 @@
 // ostream classes -*- C++ -*-
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
+// 2006, 2007
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -42,8 +43,6 @@
 
 #pragma GCC system_header
 
-#include <locale>
-
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
   template<typename _CharT, typename _Traits>
Index: include/bits/sstream.tcc
===================================================================
--- include/bits/sstream.tcc	(revision 122328)
+++ include/bits/sstream.tcc	(working copy)
@@ -1,6 +1,7 @@
 // String based streams -*- C++ -*-
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
+// 2006, 2007
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -42,8 +43,6 @@
 
 #pragma GCC system_header
 
-#include <sstream>
-
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
   template <class _CharT, class _Traits, class _Alloc>
Index: include/std/bitset
===================================================================
--- include/std/bitset	(revision 122329)
+++ include/std/bitset	(working copy)
@@ -55,7 +55,7 @@
 #include <string>
 #include <bits/functexcept.h>   // For invalid_argument, out_of_range,
                                 // overflow_error
-#include <ios>
+#include <iosfwd>
 
 #define _GLIBCXX_BITSET_BITS_PER_WORD  (__CHAR_BIT__ * sizeof(unsigned long))
 #define _GLIBCXX_BITSET_WORDS(__n) \
@@ -1228,11 +1228,14 @@
     operator>>(std::basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x)
     {
       typedef typename _Traits::char_type char_type;
+      typedef typename std::basic_istream<_CharT, _Traits>  __istream_type;
+      typedef typename __istream_type::ios_base             __ios_base;
+
       std::basic_string<_CharT, _Traits> __tmp;
       __tmp.reserve(_Nb);
 
-      std::ios_base::iostate __state = std::ios_base::goodbit;
-      typename std::basic_istream<_CharT, _Traits>::sentry __sentry(__is);
+      typename __ios_base::iostate __state = __ios_base::goodbit;
+      typename __istream_type::sentry __sentry(__is);
       if (__sentry)
 	{
 	  try
@@ -1249,7 +1252,7 @@
 		  typename _Traits::int_type __c1 = __buf->sbumpc();
 		  if (_Traits::eq_int_type(__c1, __eof))
 		    {
-		      __state |= std::ios_base::eofbit;
+		      __state |= __ios_base::eofbit;
 		      break;
 		    }
 		  else
@@ -1262,18 +1265,18 @@
 		      else if (_Traits::eq_int_type(__buf->sputbackc(__c2),
 						    __eof))
 			{
-			  __state |= std::ios_base::failbit;
+			  __state |= __ios_base::failbit;
 			  break;
 			}
 		    }
 		}
 	    }
 	  catch(...)
-	    { __is._M_setstate(std::ios_base::badbit); }
+	    { __is._M_setstate(__ios_base::badbit); }
 	}
 
       if (__tmp.empty() && _Nb)
-	__state |= std::ios_base::failbit;
+	__state |= __ios_base::failbit;
       else
 	__x._M_copy_from_string(__tmp, static_cast<size_t>(0), _Nb);
       if (__state)
Index: include/std/iomanip
===================================================================
--- include/std/iomanip	(revision 122329)
+++ include/std/iomanip	(working copy)
@@ -43,7 +43,8 @@
 #pragma GCC system_header
 
 #include <bits/c++config.h>
-#include <ios>
+#include <iosfwd>
+#include <bits/ios_base.h>
 
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
@@ -111,7 +112,7 @@
 
   template<typename _CharT, typename _Traits>
     inline basic_ostream<_CharT, _Traits>& 
-    operator<<(basic_ostream<_CharT,_Traits>& __os, _Setiosflags __f)
+    operator<<(basic_ostream<_CharT, _Traits>& __os, _Setiosflags __f)
     { 
       __os.setf(__f._M_mask); 
       return __os; 
Index: include/std/istream
===================================================================
--- include/std/istream	(revision 122328)
+++ include/std/istream	(working copy)
@@ -1,6 +1,7 @@
 // Input streams -*- C++ -*-
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
+// 2006, 2007
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -42,6 +43,8 @@
 #pragma GCC system_header
 
 #include <ios>
+#include <locale>
+#include <ostream>
 #include <limits> // For numeric_limits
 
 _GLIBCXX_BEGIN_NAMESPACE(std)
Index: include/std/complex
===================================================================
--- include/std/complex	(revision 122328)
+++ include/std/complex	(working copy)
@@ -1,6 +1,7 @@
 // The template and inlines for the -*- C++ -*- complex number classes.
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
+// 2006, 2007
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -47,7 +48,7 @@
 #include <bits/c++config.h>
 #include <bits/cpp_type_traits.h>
 #include <cmath>
-#include <sstream>
+#include <iosfwd>
 
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
@@ -481,9 +482,12 @@
 
   ///  Extraction operator for complex values.
   template<typename _Tp, typename _CharT, class _Traits>
-    basic_istream<_CharT, _Traits>&
-    operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
+    std::basic_istream<_CharT, _Traits>&
+    operator>>(std::basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
     {
+      typedef typename std::basic_istream<_CharT, _Traits>  __istream_type;
+      typedef typename __istream_type::ios_base             __ios_base;
+
       _Tp __re_x, __im_x;
       _CharT __ch;
       __is >> __ch;
@@ -496,12 +500,12 @@
 	      if (__ch == ')') 
 		__x = complex<_Tp>(__re_x, __im_x);
 	      else
-		__is.setstate(ios_base::failbit);
+		__is.setstate(__ios_base::failbit);
 	    }
 	  else if (__ch == ')') 
 	    __x = __re_x;
 	  else
-	    __is.setstate(ios_base::failbit);
+	    __is.setstate(__ios_base::failbit);
 	}
       else 
 	{
@@ -514,16 +518,10 @@
 
   ///  Insertion operator for complex values.
   template<typename _Tp, typename _CharT, class _Traits>
-    basic_ostream<_CharT, _Traits>&
-    operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x)
-    {
-      basic_ostringstream<_CharT, _Traits> __s;
-      __s.flags(__os.flags());
-      __s.imbue(__os.getloc());
-      __s.precision(__os.precision());
-      __s << '(' << __x.real() << ',' << __x.imag() << ')';
-      return __os << __s.str();
-    }
+    std::basic_ostream<_CharT, _Traits>&
+    operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+	       const complex<_Tp>& __x)
+    { return __os << '(' << __x.real() << ',' << __x.imag() << ')'; }
 
   // Values
   template<typename _Tp>
@@ -551,9 +549,9 @@
     inline _Tp
     __complex_abs(const complex<_Tp>& __z)
     {
-      _Tp __x = __z.real();
-      _Tp __y = __z.imag();
-      const _Tp __s = std::max(abs(__x), abs(__y));
+      _Tp __x = abs(__z.real());
+      _Tp __y = abs(__z.imag());
+      const _Tp __s = __x < __y ? __y : __x;
       if (__s == _Tp())  // well ...
         return __s;
       __x /= __s; 
Index: include/std/ostream
===================================================================
--- include/std/ostream	(revision 122328)
+++ include/std/ostream	(working copy)
@@ -1,6 +1,7 @@
 // Output streams -*- C++ -*-
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
+// 2006, 2007
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -42,6 +43,7 @@
 #pragma GCC system_header
 
 #include <ios>
+#include <locale>
 
 _GLIBCXX_BEGIN_NAMESPACE(std)
 

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