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] Another batch of iostreams patchlets


Hi,

tested x86-linux, approved by Benjamin.

Paolo.

//////////
2003-04-28  Paolo Carlini  <pcarlini at unitus dot it>

	* include/std/std_streambuf.h (_M_buf_size): is currently
	used only for basic_filebuf, therefore move it there.
	(basic_streambuf(), ~basic_streambuf()): Adjust.
	* include/std/std_fstream.h (_M_buf_size): Moved here.
	* include/bits/fstream.tcc (basic_filebuf()): Adjust.
2003-04-28  Paolo Carlini  <pcarlini at unitus dot it>

	* include/bits/streambuf.tcc (__copy_streambufs): Don't use
	_M_buf_size (synced input is now correctly dealt with
	elsewhere); when the output buffer is full don't fall back
	to a snextc-sputc loop, call overflow instead.
2003-04-28  Paolo Carlini  <pcarlini at unitus dot it>

	* include/bits/sstream.tcc (pbackfail): Shorten a bit (6 lines)
	the innermost 'if' by factoring out some code.
diff -urN libstdc++-v3-curr/include/bits/fstream.tcc libstdc++-v3/include/bits/fstream.tcc
--- libstdc++-v3-curr/include/bits/fstream.tcc	2003-04-26 20:42:26.000000000 +0200
+++ libstdc++-v3/include/bits/fstream.tcc	2003-04-27 17:30:53.000000000 +0200
@@ -76,7 +76,7 @@
     basic_filebuf<_CharT, _Traits>::
     basic_filebuf() : __streambuf_type(), _M_file(&_M_lock), 
     _M_state_cur(__state_type()), _M_state_beg(__state_type()), 
-    _M_buf_allocated(false), _M_last_overflowed(false),
+    _M_buf_size(BUFSIZ), _M_buf_allocated(false), _M_last_overflowed(false),
     _M_pback_cur_save(0), _M_pback_end_save(0), _M_pback_init(false)
     { this->_M_buf_unified = true; }
 
diff -urN libstdc++-v3-curr/include/std/std_fstream.h libstdc++-v3/include/std/std_fstream.h
--- libstdc++-v3-curr/include/std/std_fstream.h	2003-04-26 20:42:26.000000000 +0200
+++ libstdc++-v3/include/std/std_fstream.h	2003-04-27 17:42:59.000000000 +0200
@@ -45,6 +45,7 @@
 #include <istream>
 #include <ostream>
 #include <locale>	// For codecvt
+#include <cstdio>       // For SEEK_SET, SEEK_CUR, SEEK_END, BUFSIZ     
 #include <bits/basic_file.h>
 #include <bits/gthr.h>
 
@@ -113,6 +114,13 @@
       __state_type		_M_state_cur;
       __state_type 		_M_state_beg;
 
+      /**
+       *  @if maint
+       *  Actual size of internal buffer.
+       *  @endif
+      */
+      size_t			_M_buf_size;
+
       // Set iff _M_buf is allocated memory from _M_allocate_internal_buffer.
       /**
        *  @if maint
@@ -209,6 +217,7 @@
       ~basic_filebuf()
       {
 	this->close();
+	_M_buf_size = 0;
 	_M_last_overflowed = false;
       }
 
diff -urN libstdc++-v3-curr/include/std/std_streambuf.h libstdc++-v3/include/std/std_streambuf.h
--- libstdc++-v3-curr/include/std/std_streambuf.h	2003-04-22 19:32:25.000000000 +0200
+++ libstdc++-v3/include/std/std_streambuf.h	2003-04-27 17:42:51.000000000 +0200
@@ -44,7 +44,6 @@
 
 #include <bits/c++config.h>
 #include <iosfwd>
-#include <cstdio> 	// For SEEK_SET, SEEK_CUR, SEEK_END
 #include <bits/localefwd.h>
 #include <bits/ios_base.h>
 
@@ -172,14 +171,6 @@
 
       /**
        *  @if maint
-       *  Actual size of allocated internal buffer. Unused for sstreams,
-       *  which have readily available _M_string.capacity().
-       *  @endif
-      */
-      size_t			_M_buf_size;
-
-      /**
-       *  @if maint
        *  True iff _M_in_* and _M_out_* buffers should always point to
        *  the same place.  True for fstreams, false for sstreams.
        *  @endif
@@ -278,7 +269,6 @@
       ~basic_streambuf() 
       {
 	_M_buf_unified = false;
-	_M_buf_size = 0;
 	_M_mode = ios_base::openmode(0);
       }
 
@@ -477,7 +467,7 @@
        *  - this is not an error
       */
       basic_streambuf()
-      : _M_buf(NULL), _M_buf_size(BUFSIZ), _M_buf_unified(false),
+      : _M_buf(NULL), _M_buf_unified(false),
       _M_in_beg(0), _M_in_cur(0), _M_in_end(0), _M_out_beg(0),
       _M_out_cur(0), _M_out_end(0), _M_out_lim(0),
       _M_mode(ios_base::openmode(0)), _M_buf_locale(locale()) 
diff -prN libstdc++-v3-orig/include/bits/streambuf.tcc libstdc++-v3/include/bits/streambuf.tcc
*** libstdc++-v3-orig/include/bits/streambuf.tcc	Mon Apr 28 23:10:53 2003
--- libstdc++-v3/include/bits/streambuf.tcc	Mon Apr 28 23:57:20 2003
*************** namespace std 
*** 188,195 ****
        typedef typename _Traits::off_type	off_type;
  
        streamsize __ret = 0;
-       const off_type __buf_size =
- 	__sbin->_M_buf_size > 0 ? __sbin->_M_buf_size : 1;
        try 
  	{
  	  for (;;)
--- 188,193 ----
*************** namespace std 
*** 208,217 ****
   	      else 
  		{
  		  streamsize __charsread;
! 		  const off_type __size = std::min(__buf_size,
! 						   off_type(__sbout->_M_out_end
! 						   - __sbout->_M_out_cur));
! 		  if (__size > 1)
  		    {
  		      _CharT* __buf =
  			static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
--- 206,214 ----
   	      else 
  		{
  		  streamsize __charsread;
! 		  const off_type __size = __sbout->_M_out_end
! 		                          - __sbout->_M_out_cur;
! 		  if (__size)
  		    {
  		      _CharT* __buf =
  			static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
*************** namespace std 
*** 224,238 ****
  		  else
  		    {
  		      __xtrct = __charsread = 0;
! 		      int_type __c = __sbin->sgetc();
! 		      while (!_Traits::eq_int_type(__c, _Traits::eof()))
  			{
  			  ++__charsread;
! 			  if (_Traits::eq_int_type(__sbout->sputc(_Traits::to_char_type(__c)),
  						   _Traits::eof()))
  			    break;
  			  ++__xtrct;
! 			  __c = __sbin->snextc();
  			}
  		    }		      
  		  __ret += __xtrct;
--- 221,235 ----
  		  else
  		    {
  		      __xtrct = __charsread = 0;
! 		      const int_type __c = __sbin->sgetc();
! 		      if (!_Traits::eq_int_type(__c, _Traits::eof()))
  			{
  			  ++__charsread;
! 			  if (_Traits::eq_int_type(__sbout->overflow(__c),
  						   _Traits::eof()))
  			    break;
  			  ++__xtrct;
! 			  __sbin->sbumpc();
  			}
  		    }		      
  		  __ret += __xtrct;
diff -prN libstdc++-v3-curr/include/bits/sstream.tcc libstdc++-v3/include/bits/sstream.tcc
*** libstdc++-v3-curr/include/bits/sstream.tcc	Mon Apr 21 23:44:43 2003
--- libstdc++-v3/include/bits/sstream.tcc	Sun Apr 27 21:20:12 2003
*************** namespace std
*** 55,78 ****
        // Order these tests done in is unspecified by the standard.
        if (__testpos)
  	{
! 	  if (traits_type::eq(traits_type::to_char_type(__c),
! 			      this->_M_in_cur[-1])
! 	      && !__testeof)
! 	    {
! 	      --this->_M_in_cur;
! 	      __ret = __c;
! 	    }
! 	  else if (!__testeof)
  	    {
- 	      --this->_M_in_cur;
  	      *this->_M_in_cur = traits_type::to_char_type(__c);
  	      __ret = __c;
  	    }
- 	  else if (__testeof)
- 	    {
- 	      --this->_M_in_cur;
- 	      __ret = traits_type::not_eof(__c);
- 	    }
  	}
        return __ret;
      }
--- 55,72 ----
        // Order these tests done in is unspecified by the standard.
        if (__testpos)
  	{
! 	  const bool __testeq = traits_type::eq(traits_type::to_char_type(__c),
! 						this->_M_in_cur[-1]);
! 	  --this->_M_in_cur;
! 	  if (!__testeof && __testeq)
! 	    __ret = __c;
! 	  else if (__testeof)
! 	    __ret = traits_type::not_eof(__c);
! 	  else
  	    {
  	      *this->_M_in_cur = traits_type::to_char_type(__c);
  	      __ret = __c;
  	    }
  	}
        return __ret;
      }


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