This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] istreambuf_iterator::operator++ simplification
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Cc: Nathan Myers <ncm at cantrip dot org>
- Date: Tue, 23 Nov 2004 14:22:59 +0100
- Subject: [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;
}