From 5e77a357679635fe15bd3c4e4c904c6f40f81a13 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sun, 20 Apr 2003 15:54:45 +0200 Subject: [PATCH] sstream.tcc (pbackfail): Remove redundant NULL pointer check from test involving _M_in_*. 2003-04-20 Paolo Carlini * include/bits/sstream.tcc (pbackfail): Remove redundant NULL pointer check from test involving _M_in_*. (overflow, seekoff, seekpos): Const qualify bool variables. * include/std/std_sstream.h (underflow): Remove redundant NULL pointer check from test involving _M_in_*. (_M_really_sync): Const qualify bool variables. * src/fstream.cc (_M_underflow_common): Remove redundant NULL pointer check from test involving _M_in_*, const qualify bool variables. * include/std/std_streambuf.h (sgetc): Remove redundant variable. From-SVN: r65853 --- libstdc++-v3/ChangeLog | 15 +++++++++++++++ libstdc++-v3/include/bits/sstream.tcc | 18 ++++++++++-------- libstdc++-v3/include/std/std_sstream.h | 6 +++--- libstdc++-v3/include/std/std_streambuf.h | 6 ++---- libstdc++-v3/src/fstream.cc | 24 ++++++++++++------------ 5 files changed, 42 insertions(+), 27 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0837473b35d..6f46b916fb3 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,18 @@ +2003-04-20 Paolo Carlini + + * include/bits/sstream.tcc (pbackfail): Remove redundant + NULL pointer check from test involving _M_in_*. + (overflow, seekoff, seekpos): Const qualify bool variables. + * include/std/std_sstream.h (underflow): Remove redundant + NULL pointer check from test involving _M_in_*. + (_M_really_sync): Const qualify bool variables. + * src/fstream.cc (_M_underflow_common): Remove redundant + NULL pointer check from test involving _M_in_*, const qualify + bool variables. + + * include/std/std_streambuf.h (sgetc): Remove redundant + variable. + 2003-04-18 Paolo Carlini According to 5.9 para 2 (second bullet) for pointers p, q diff --git a/libstdc++-v3/include/bits/sstream.tcc b/libstdc++-v3/include/bits/sstream.tcc index ab3298c1022..9160b5a8a9d 100644 --- a/libstdc++-v3/include/bits/sstream.tcc +++ b/libstdc++-v3/include/bits/sstream.tcc @@ -47,8 +47,9 @@ namespace std pbackfail(int_type __c) { int_type __ret = traits_type::eof(); - bool __testeof = traits_type::eq_int_type(__c, traits_type::eof()); - bool __testpos = this->_M_in_cur && this->_M_in_beg < this->_M_in_cur; + const bool __testeof = + traits_type::eq_int_type(__c, traits_type::eof()); + const bool __testpos = this->_M_in_beg < this->_M_in_cur; // Try to put back __c into input sequence in one of three ways. // Order these tests done in is unspecified by the standard. @@ -80,11 +81,12 @@ namespace std basic_stringbuf<_CharT, _Traits, _Alloc>:: overflow(int_type __c) { - bool __testout = this->_M_mode & ios_base::out; + const bool __testout = this->_M_mode & ios_base::out; if (__builtin_expect(!__testout, false)) return traits_type::eof(); - bool __testeof = traits_type::eq_int_type(__c, traits_type::eof()); + const bool __testeof = + traits_type::eq_int_type(__c, traits_type::eof()); if (__builtin_expect(__testeof, false)) return traits_type::not_eof(__c); @@ -94,7 +96,7 @@ namespace std // suit particular needs. __size_type __len = std::max(__size_type(_M_string.capacity() + 1), __size_type(512)); - bool __testput = this->_M_out_cur < this->_M_out_end; + const bool __testput = this->_M_out_cur < this->_M_out_end; if (__builtin_expect(!__testput && __len > _M_string.max_size(), false)) return traits_type::eof(); @@ -123,7 +125,7 @@ namespace std pos_type __ret = pos_type(off_type(-1)); bool __testin = (ios_base::in & this->_M_mode & __mode) != 0; bool __testout = (ios_base::out & this->_M_mode & __mode) != 0; - bool __testboth = __testin && __testout && __way != ios_base::cur; + const bool __testboth = __testin && __testout && __way != ios_base::cur; __testin &= !(__mode & ios_base::out); __testout &= !(__mode & ios_base::in); @@ -189,8 +191,8 @@ namespace std off_type __pos = __sp; // Use streamoff operator to do conversion. char_type* __beg = NULL; char_type* __end = NULL; - bool __testin = (ios_base::in & this->_M_mode & __mode) != 0; - bool __testout = (ios_base::out & this->_M_mode & __mode) != 0; + const bool __testin = (ios_base::in & this->_M_mode & __mode) != 0; + const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0; // NB: Ordered. bool __testposi = false; diff --git a/libstdc++-v3/include/std/std_sstream.h b/libstdc++-v3/include/std/std_sstream.h index 635e8ed61fb..48b81cd8d95 100644 --- a/libstdc++-v3/include/std/std_sstream.h +++ b/libstdc++-v3/include/std/std_sstream.h @@ -190,7 +190,7 @@ namespace std virtual int_type underflow() { - if (this->_M_in_cur && this->_M_in_cur < this->_M_in_end) + if (this->_M_in_cur < this->_M_in_end) return traits_type::to_int_type(*gptr()); else return traits_type::eof(); @@ -260,8 +260,8 @@ namespace std virtual void _M_really_sync(char_type* __base, __size_type __i, __size_type __o) { - bool __testin = this->_M_mode & ios_base::in; - bool __testout = this->_M_mode & ios_base::out; + const bool __testin = this->_M_mode & ios_base::in; + const bool __testout = this->_M_mode & ios_base::out; __size_type __len = _M_string.size(); this->_M_buf = __base; diff --git a/libstdc++-v3/include/std/std_streambuf.h b/libstdc++-v3/include/std/std_streambuf.h index b180c877940..658b02f46cc 100644 --- a/libstdc++-v3/include/std/std_streambuf.h +++ b/libstdc++-v3/include/std/std_streambuf.h @@ -452,12 +452,10 @@ namespace std int_type sgetc() { - int_type __ret; if (_M_in_cur < _M_in_end) - __ret = traits_type::to_int_type(*(this->gptr())); + return traits_type::to_int_type(*(this->gptr())); else - __ret = this->underflow(); - return __ret; + return this->underflow(); } /** diff --git a/libstdc++-v3/src/fstream.cc b/libstdc++-v3/src/fstream.cc index 0f9b2abd2c4..e79659d38a7 100644 --- a/libstdc++-v3/src/fstream.cc +++ b/libstdc++-v3/src/fstream.cc @@ -41,10 +41,10 @@ namespace std basic_filebuf::_M_underflow_common(bool __bump) { int_type __ret = traits_type::eof(); - bool __testin = _M_mode & ios_base::in; - bool __testout = _M_mode & ios_base::out; + const bool __testin = _M_mode & ios_base::in; + const bool __testout = _M_mode & ios_base::out; // Sync with stdio. - bool __sync = _M_buf_size <= 1; + const bool __sync = _M_buf_size <= 1; if (__testin) { @@ -54,7 +54,7 @@ namespace std if (_M_pback_init) _M_pback_destroy(); - if (_M_in_cur && _M_in_cur < _M_in_end) + if (_M_in_cur < _M_in_end) { __ret = traits_type::to_int_type(*_M_in_cur); if (__bump) @@ -64,8 +64,8 @@ namespace std // Sync internal and external buffers. // NB: __testget -> __testput as _M_buf_unified here. - bool __testget = _M_in_cur && _M_in_beg < _M_in_cur; - bool __testinit = _M_is_indeterminate(); + const bool __testget = _M_in_beg < _M_in_cur; + const bool __testinit = _M_is_indeterminate(); if (__testget) { if (__testout) @@ -123,10 +123,10 @@ namespace std basic_filebuf::_M_underflow_common(bool __bump) { int_type __ret = traits_type::eof(); - bool __testin = _M_mode & ios_base::in; - bool __testout = _M_mode & ios_base::out; + const bool __testin = _M_mode & ios_base::in; + const bool __testout = _M_mode & ios_base::out; // Sync with stdio. - bool __sync = _M_buf_size <= 1; + const bool __sync = _M_buf_size <= 1; if (__testin) { @@ -136,7 +136,7 @@ namespace std if (_M_pback_init) _M_pback_destroy(); - if (_M_in_cur && _M_in_cur < _M_in_end) + if (_M_in_cur < _M_in_end) { __ret = traits_type::to_int_type(*_M_in_cur); if (__bump) @@ -146,8 +146,8 @@ namespace std // Sync internal and external buffers. // NB: __testget -> __testput as _M_buf_unified here. - bool __testget = _M_in_cur && _M_in_beg < _M_in_cur; - bool __testinit = _M_is_indeterminate(); + const bool __testget = _M_in_beg < _M_in_cur; + const bool __testinit = _M_is_indeterminate(); if (__testget) { if (__testout)