This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] 3 more iostreams patchlets
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 01 May 2003 18:59:25 +0200
- Subject: [v3] 3 more iostreams patchlets
Hi,
tested x86-linux, applied to trunk.
Paolo.
////////
2003-05-01 Paolo Carlini <pcarlini@unitus.it>
* include/bits/streambuf.tcc (basic_streambuf::xsgetn):
Const-ify some variables.
(basic_streambuf::xsputn): Likewise; change the type of some
variables to size_t.
(__copy_streambufs): Change some variables to size_t.
2003-05-01 Paolo Carlini <pcarlini@unitus.it>
* include/std/std_sstream.h (str()): Avoid constructing
a basic_string temporary not only when it would turn out
to be zero-sized but also when identical to the current
_M_string buffer.
2003-05-01 Paolo Carlini <pcarlini@unitus.it>
* include/ext/stdio_filebuf.h
(stdio_filebuf(int, std::ios_base::openmode, bool, size_t),
stdio_filebuf(std::__c_file*, std::ios_base::openmode, size_t)):
Shorten a bit (-10 lines) by factoring out some code.
diff -urN libstdc++-v3-orig/include/bits/streambuf.tcc libstdc++-v3/include/bits/streambuf.tcc
--- libstdc++-v3-orig/include/bits/streambuf.tcc 2003-04-29 00:15:58.000000000 +0200
+++ libstdc++-v3/include/bits/streambuf.tcc 2003-05-01 12:23:29.000000000 +0200
@@ -114,11 +114,11 @@
streamsize __ret = 0;
while (__ret < __n)
{
- size_t __buf_len = _M_in_end - _M_in_cur;
+ const size_t __buf_len = _M_in_end - _M_in_cur;
if (__buf_len > 0)
{
- size_t __remaining = __n - __ret;
- size_t __len = std::min(__buf_len, __remaining);
+ const size_t __remaining = __n - __ret;
+ const size_t __len = std::min(__buf_len, __remaining);
traits_type::copy(__s, _M_in_cur, __len);
__ret += __len;
__s += __len;
@@ -127,7 +127,7 @@
if (__ret < __n)
{
- int_type __c = this->uflow();
+ const int_type __c = this->uflow();
if (!traits_type::eq_int_type(__c, traits_type::eof()))
{
traits_type::assign(*__s++, traits_type::to_char_type(__c));
@@ -148,11 +148,11 @@
streamsize __ret = 0;
while (__ret < __n)
{
- off_type __buf_len = _M_out_end - _M_out_cur;
+ const size_t __buf_len = _M_out_end - _M_out_cur;
if (__buf_len > 0)
{
- off_type __remaining = __n - __ret;
- off_type __len = std::min(__buf_len, __remaining);
+ const size_t __remaining = __n - __ret;
+ const size_t __len = std::min(__buf_len, __remaining);
traits_type::copy(_M_out_cur, __s, __len);
__ret += __len;
__s += __len;
@@ -161,7 +161,7 @@
if (__ret < __n)
{
- int_type __c = this->overflow(traits_type::to_int_type(*__s));
+ const int_type __c = this->overflow(traits_type::to_int_type(*__s));
if (!traits_type::eq_int_type(__c, traits_type::eof()))
{
++__ret;
@@ -185,7 +185,6 @@
basic_streambuf<_CharT, _Traits>* __sbout)
{
typedef typename _Traits::int_type int_type;
- typedef typename _Traits::off_type off_type;
streamsize __ret = 0;
try
@@ -193,8 +192,8 @@
for (;;)
{
streamsize __xtrct;
- const off_type __avail = __sbin->_M_in_end
- - __sbin->_M_in_cur;
+ const size_t __avail = __sbin->_M_in_end
+ - __sbin->_M_in_cur;
if (__avail)
{
__xtrct = __sbout->sputn(__sbin->_M_in_cur, __avail);
@@ -206,8 +205,8 @@
else
{
streamsize __charsread;
- const off_type __size = __sbout->_M_out_end
- - __sbout->_M_out_cur;
+ const size_t __size = __sbout->_M_out_end
+ - __sbout->_M_out_cur;
if (__size)
{
_CharT* __buf =
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-04-12 21:21:34.000000000 +0200
+++ libstdc++-v3/include/ext/stdio_filebuf.h 2003-05-01 10:27:58.000000000 +0200
@@ -124,17 +124,12 @@
if (this->is_open())
{
this->_M_mode = __mode;
+ this->_M_buf_size = __size;
if (__size > 0 && __size < 4)
- {
- // Specify not to use an allocated buffer.
- this->_M_buf = _M_unbuf;
- this->_M_buf_size = __size;
- }
+ // Specify not to use an allocated buffer.
+ this->_M_buf = _M_unbuf;
else
- {
- this->_M_buf_size = __size;
- _M_allocate_internal_buffer();
- }
+ _M_allocate_internal_buffer();
_M_set_indeterminate();
}
}
@@ -148,17 +143,12 @@
if (this->is_open())
{
this->_M_mode = __mode;
+ this->_M_buf_size = __size;
if (__size > 0 && __size < 4)
- {
- // Specify not to use an allocated buffer.
- this->_M_buf = _M_unbuf;
- this->_M_buf_size = __size;
- }
+ // Specify not to use an allocated buffer.
+ this->_M_buf = _M_unbuf;
else
- {
- this->_M_buf_size = __size;
- _M_allocate_internal_buffer();
- }
+ _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-04-29 19:47:38.000000000 +0200
+++ libstdc++-v3/include/std/std_sstream.h 2003-05-01 11:22:45.000000000 +0200
@@ -140,14 +140,12 @@
// represents the size of the initial string used to
// created the buffer, and may not be the correct size of
// the current stringbuf internal buffer.
- __size_type __len = _M_string.size();
- __size_type __nlen = this->_M_out_lim - this->_M_out_beg;
- if (__nlen)
- {
- __len = std::max(__nlen, __len);
- __ret = __string_type(this->_M_out_beg,
- this->_M_out_beg + __len);
- }
+ const __size_type __len = _M_string.size();
+ const __size_type __nlen = this->_M_out_lim
+ - this->_M_out_beg;
+ if (__nlen > __len)
+ __ret = __string_type(this->_M_out_beg,
+ this->_M_out_beg + __nlen);
}
return __ret;
}