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] Remove _M_is_indeterminate, simplify _M_underflow.


Hi again,

this is more substantive (and more interesting!).
Consider the beginning of _M_underflow:

//

   if (_M_in_cur < _M_in_end)
     {
       __ret = traits_type::to_int_type(*_M_in_cur);
       if (__bump)
         _M_move_in_cur(1);
       return __ret;
     }

   // Sync internal and external buffers.
   // NB: __testget -> __testput as _M_buf_unified here.
   const bool __testget = _M_in_beg < _M_in_cur;
   const bool __testinit = _M_is_indeterminate();
   if (__testget)
     {
       if (__testout)
         _M_overflow();
       else if (_M_in_cur != _M_filepos)
         _M_file.seekoff(_M_in_cur - _M_filepos,
                         ios_base::cur, __testsync, ios_base::in);
     }

   if (__testinit || __testget)
     {
       streamsize __elen = 0;
       streamsize __ilen = 0;

//

After the first 'if', either _M_in_cur == _M_in_end or they are both
NULL. Therefore, __testinit either is !__testget or is false because
there is no buffer, i.e., is redundant and can be removed, together
with _M_is_indeterminate(), not used anywhere else.

Tested x86-linux (+ 27_io/objects by hand + some other sanity checks).

Paolo.

//////////
2003-05-04  Paolo Carlini  <pcarlini@unitus.it>

	* include/std/std_fstream.h (_M_is_indeterminate): Remove.
	* src/fstream.cc
	(basic_filebuf<char/wchar_t>::_M_underflow): Simplify: either
	there is no buffer or __testget == !__testinit.
diff -urN libstdc++-v3-5/include/std/std_fstream.h libstdc++-v3/include/std/std_fstream.h
--- libstdc++-v3-5/include/std/std_fstream.h	2003-05-04 01:02:36.000000000 +0200
+++ libstdc++-v3/include/std/std_fstream.h	2003-05-04 13:17:02.000000000 +0200
@@ -485,30 +485,6 @@
 	  }
 	_M_filepos = this->_M_buf + __off;
       }
-
-      /**
-       *  @if maint
-       *  @doctodo
-       *  @endif
-      */
-      bool
-      _M_is_indeterminate(void)
-      { 
-	const bool __testin = this->_M_mode & ios_base::in;
-	const bool __testout = this->_M_mode & ios_base::out;
-	bool __ret = false;
-	// Don't return true if unbuffered.
-	if (this->_M_buf)
-	  {
-	    if (__testin)
-	      __ret = this->_M_in_beg == this->_M_in_cur
-		&& this->_M_in_cur == this->_M_in_end;
-	    if (__testout)
-	      __ret = this->_M_out_beg == this->_M_out_cur
-		&& this->_M_out_cur == this->_M_out_lim;
-	  }
-	return __ret;
-      }
     };
 
   // Explicit specialization declarations, defined in src/fstream.cc.
diff -urN libstdc++-v3-5/src/fstream.cc libstdc++-v3/src/fstream.cc
--- libstdc++-v3-5/src/fstream.cc	2003-05-03 18:34:06.000000000 +0200
+++ libstdc++-v3/src/fstream.cc	2003-05-04 13:15:44.000000000 +0200
@@ -64,7 +64,6 @@
 	  // Sync internal and external buffers.
 	  // NB: __testget -> __testput as _M_buf_unified here.
 	  const bool __testget = _M_in_beg < _M_in_cur;
-	  const bool __testinit = _M_is_indeterminate();
 	  if (__testget)
 	    {
 	      if (__testout)
@@ -74,7 +73,7 @@
 				ios_base::cur, __testsync, ios_base::in);
 	    }
 
-	  if (__testinit || __testget)
+	  if (_M_buf_size)
 	    {
 	      streamsize __elen = 0;
 	      streamsize __ilen = 0;
@@ -143,7 +142,6 @@
 	  // Sync internal and external buffers.
 	  // NB: __testget -> __testput as _M_buf_unified here.
 	  const bool __testget = _M_in_beg < _M_in_cur;
-	  const bool __testinit = _M_is_indeterminate();
 	  if (__testget)
 	    {
 	      if (__testout)
@@ -153,7 +151,7 @@
 				ios_base::cur, __testsync, ios_base::in);
 	    }
 
-	  if (__testinit || __testget)
+	  if (_M_buf_size)
 	    {
 	      streamsize __elen = 0;
 	      streamsize __ilen = 0;

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