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] istreambuf_iterator::operator++ simplification


Hi,

in private email, Nathan very kindly gave a lot of interesting suggestions
for further improving and streamlining istreambuf_iterator; I'm separately
and incrementally testing and benchmarking each one.

The below just notices that both operator++ can avoid checking the return
value of sbumpc() and it's worth a small but consistent improvement in
in many different tests.

Regtested x86-linux, will wait 'til this evening (italian time) in case
of comments.

Paolo.

/////////////////
2004-11-23  Nathan Myers  <ncm@cantrip.org>

	* include/bits/streambuf_iterator.h
	(istreambuf_iterator<>::operator++(), operator++(int)): Don't
	check unnecessarily the return value of _M_sbuf->sbumpc().
--- streambuf_iterator.h.~1.20.~	2004-11-14 23:54:24.000000000 +0100
+++ streambuf_iterator.h	2004-11-23 12:14:52.000000000 +0100
@@ -110,11 +110,11 @@
 	__glibcxx_requires_cond(!_M_at_eof(),
 				_M_message(__gnu_debug::__msg_inc_istreambuf)
 				._M_iterator(*this));
-	const int_type __eof = traits_type::eof();
-	if (_M_sbuf && traits_type::eq_int_type(_M_sbuf->sbumpc(), __eof))
-	  _M_sbuf = 0;
-	else
-	  _M_c = __eof;
+	if (_M_sbuf)
+	  {
+	    _M_sbuf->sbumpc();
+	    _M_c = traits_type::eof();
+	  }
 	return *this;
       }
 
@@ -126,14 +126,12 @@
 				_M_message(__gnu_debug::__msg_inc_istreambuf)
 				._M_iterator(*this));
 
-	const int_type __eof = traits_type::eof();
 	istreambuf_iterator __old = *this;
-	if (_M_sbuf
-	    && traits_type::eq_int_type((__old._M_c = _M_sbuf->sbumpc()),
-					__eof))
-	  _M_sbuf = 0;
-	else
-	  _M_c = __eof;
+	if (_M_sbuf)
+	  {
+	    __old._M_c = _M_sbuf->sbumpc();
+	    _M_c = traits_type::eof();
+	  }
 	return __old;
       }
 

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