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]

[RFC, trunk] What about removing _M_buf_size_opt?


Hi,

while working on the issues which I mentioned earlier today, it
occurred to me that perhaps for trunk we can remove _M_buf_size_opt
completely!

In the spirit of Nathan's maxim indeed: "... cut and _cut_ and *cut*!"

As already pointed out by Benjamin some time ago (0 or 1 in the
unbuffered case?!?) its very semantics its quite confused: this is at
the root of the bug which I fixed for 3.3 in the previous posting.

I'm attaching here the preliminary patch which I have successfully
regression tested.

Opinions?

Paolo.

/////////
diff -urN libstdc++-v3-orig/include/bits/fstream.tcc libstdc++-v3/include/bits/fstream.tcc
--- libstdc++-v3-orig/include/bits/fstream.tcc	2003-03-28 18:45:23.000000000 +0100
+++ libstdc++-v3/include/bits/fstream.tcc	2003-03-29 18:37:18.000000000 +0100
@@ -44,10 +44,8 @@
     basic_filebuf<_CharT, _Traits>::
     _M_allocate_internal_buffer()
     {
-      if (!this->_M_buf && this->_M_buf_size_opt)
+      if (!this->_M_buf && this->_M_buf_size)
 	{
-	  this->_M_buf_size = this->_M_buf_size_opt;
-
 	  // Allocate internal buffer...
 	  this->_M_buf = new char_type[this->_M_buf_size];
 	  // ... and consistently set the end of buffer pointer.
@@ -356,7 +354,7 @@
     {
       int_type __ret = traits_type::eof();
       bool __testput = this->_M_out_cur && this->_M_out_beg < this->_M_out_lim;
-      bool __testunbuffered = _M_file.is_open() && !this->_M_buf_size_opt;
+      bool __testunbuffered = _M_file.is_open() && !this->_M_buf_size;
       // Sync with stdio.
       bool __sync = this->_M_buf_size == 1;
 
@@ -417,7 +415,7 @@
     setbuf(char_type* __s, streamsize __n)
     {
       if (!this->is_open() && __s == 0 && __n == 0)
-	this->_M_buf_size_opt = 0;
+	this->_M_buf_size = 0;
       else if (__s && __n)
 	{
 	  // This is implementation-defined behavior, and assumes
@@ -430,7 +428,7 @@
 	  
 	  // Step 2: Use the external array.
 	  this->_M_buf = __s;
-	  this->_M_buf_size_opt = this->_M_buf_size = __n;
+	  this->_M_buf_size = __n;
 	  // Consistently set the end of buffer pointer.
 	  this->_M_out_end = this->_M_buf + this->_M_buf_size;
 	  _M_set_indeterminate();
diff -urN libstdc++-v3-orig/include/bits/sstream.tcc libstdc++-v3/include/bits/sstream.tcc
--- libstdc++-v3-orig/include/bits/sstream.tcc	2003-02-24 19:22:57.000000000 +0100
+++ libstdc++-v3/include/bits/sstream.tcc	2003-03-29 19:05:01.000000000 +0100
@@ -87,10 +87,11 @@
       if (__builtin_expect(__testeof, false))
 	return traits_type::not_eof(__c);
 
-      // In virtue of DR 169 (TC) we are allowed to grow more than
-      // one char the first time and also...
-      __size_type __len =
-	std::max(_M_string.capacity() + 1, this->_M_buf_size_opt);
+      // NB: start stringstream buffers at 512 chars. This is an
+      // experimental value (pronounced "arbitrary" in some of the
+      // hipper english-speaking countries), and can be changed to
+      // suit particular needs.
+      __size_type __len = std::max(_M_string.capacity() + 1, size_t(512));
 
       bool __testwrite = _M_out_buf_size();
       if (__builtin_expect(!__testwrite && __len > _M_string.max_size(), false))
@@ -102,8 +103,9 @@
 	{
 	  // Force-allocate, re-sync.
 	  _M_string = this->str();
-	  // ... the next times. That's easy to implement thanks to the
-	  // exponential growth policy builtin into basic_string.
+	  // In virtue of DR 169 (TC) we are allowed to grow more than
+	  // one char. That's easy to implement thanks to the exponential
+	  // growth policy builtin into basic_string.
 	  _M_string.reserve(__len);
 	  _M_really_sync(this->_M_in_cur - this->_M_in_beg, 
 			 this->_M_out_cur - this->_M_out_beg);
diff -urN libstdc++-v3-orig/include/bits/streambuf.tcc libstdc++-v3/include/bits/streambuf.tcc
--- libstdc++-v3-orig/include/bits/streambuf.tcc	2003-03-08 09:16:05.000000000 +0100
+++ libstdc++-v3/include/bits/streambuf.tcc	2003-03-29 18:40:56.000000000 +0100
@@ -194,7 +194,7 @@
       streamsize __bufsize = __sbin->in_avail();
       streamsize __xtrct;
       const typename _Traits::off_type __size_opt =
-	__sbin->_M_buf_size_opt > 0 ? __sbin->_M_buf_size_opt : 1;
+	__sbin->_M_buf_size > 0 ? __sbin->_M_buf_size : 1;
 
       try 
 	{
diff -urN libstdc++-v3-orig/include/ext/stdio_filebuf.h libstdc++-v3/include/ext/stdio_filebuf.h
--- libstdc++-v3-orig/include/ext/stdio_filebuf.h	2003-02-11 11:43:49.000000000 +0100
+++ libstdc++-v3/include/ext/stdio_filebuf.h	2003-03-29 18:43:09.000000000 +0100
@@ -126,14 +126,12 @@
 	  this->_M_mode = __mode;
 	  if (__size > 0 && __size < 4)
 	    {
-	      // Specify unbuffered.
 	      this->_M_buf = _M_unbuf;
 	      this->_M_buf_size = __size;
-	      this->_M_buf_size_opt = 0;
 	    }
 	  else
 	    {
-	      this->_M_buf_size_opt = __size;
+	      this->_M_buf_size = __size;
 	      _M_allocate_internal_buffer();
 	    }
 	  _M_set_indeterminate();
@@ -151,14 +149,12 @@
 	  this->_M_mode = __mode;
 	  if (__size > 0 && __size < 4)
 	    {
-	      // Specify unbuffered.
 	      this->_M_buf = _M_unbuf;
 	      this->_M_buf_size = __size;
-	      this->_M_buf_size_opt = 0;
 	    }
 	  else
 	    {
-	      this->_M_buf_size_opt = __size;
+	      this->_M_buf_size = __size;
 	      _M_allocate_internal_buffer();
 	    }
 	  _M_set_indeterminate();
diff -urN libstdc++-v3-orig/include/std/std_sstream.h libstdc++-v3/include/std/std_sstream.h
--- libstdc++-v3-orig/include/std/std_sstream.h	2003-03-29 09:14:25.000000000 +0100
+++ libstdc++-v3/include/std/std_sstream.h	2003-03-29 18:47:23.000000000 +0100
@@ -174,11 +174,6 @@
       void
       _M_stringbuf_init(ios_base::openmode __mode)
       {
-	// NB: Start ostringstream buffers at 512 bytes. This is an
-	// experimental value (pronounced "arbitrary" in some of the
-	// hipper english-speaking countries), and can be changed to
-	// suit particular needs.
-	this->_M_buf_size_opt = 512;
 	this->_M_mode = __mode;
 	if (this->_M_mode & (ios_base::ate | ios_base::app))
 	  _M_really_sync(0, _M_string.size());
diff -urN libstdc++-v3-orig/include/std/std_streambuf.h libstdc++-v3/include/std/std_streambuf.h
--- libstdc++-v3-orig/include/std/std_streambuf.h	2003-02-24 19:22:57.000000000 +0100
+++ libstdc++-v3/include/std/std_streambuf.h	2003-03-29 18:51:32.000000000 +0100
@@ -180,13 +180,6 @@
 
       /**
        *  @if maint
-       *  Optimal or preferred size of internal buffer, in bytes.
-       *  @endif
-      */
-      size_t			_M_buf_size_opt;
-
-      /**
-       *  @if maint
        *  True iff _M_in_* and _M_out_* buffers should always point to
        *  the same place.  True for fstreams, false for sstreams.
        *  @endif
@@ -350,7 +343,6 @@
       {
 	_M_buf_unified = false;
 	_M_buf_size = 0;
-	_M_buf_size_opt = 0;
 	_M_mode = ios_base::openmode(0);
       }
 
@@ -562,9 +554,9 @@
        *  - this is not an error
       */
       basic_streambuf()
-      : _M_buf(NULL), _M_buf_size(0), _M_buf_size_opt(BUFSIZ), 
-      _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_buf(NULL), _M_buf_size(BUFSIZ), _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()), 
       _M_pback_cur_save(0), _M_pback_end_save(0), 
       _M_pback_init(false)
diff -urN libstdc++-v3-orig/testsuite/27_io/filebuf_virtuals.cc libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc
--- libstdc++-v3-orig/testsuite/27_io/filebuf_virtuals.cc	2003-03-18 00:50:40.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc	2003-03-29 18:53:09.000000000 +0100
@@ -86,7 +86,7 @@
 {
  public:
   void
-  set_size(int_type __size) { _M_buf_size_opt = __size; }
+  set_size(int_type __size) { _M_buf_size = __size; }
 };
 
 derived_filebuf fb_01; // in 

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