This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[v3] remove redundant init calls


First of two initialization clean ups. This one streamlines the calls
to basic_ios::init across the iostreams hierarchy. The next will deal
with a zero-allocation approach to __locale_cache and the standard
stream objects.

tested x86/linux

2003-03-28  Benjamin Kosnik  <bkoz at redhat dot com>

	* include/std/std_sstream.h (basic_istringstream): Adjust
	initialization.
	(basic_ostringstream): Same.
	(basic_stringstream): Same.	
	* include/std/std_fstream.h (basic_ifstream): Adjust initialization.
	(basic_ofstream): Same.
	(basic_fstream): Same.
	* include/std/std_ostream.h (basic_ostrem): Add protected ctor
	that does not call init.
	* include/std/std_istream.h (basic_istream): Same.		
	(basic_iostream): Construct istream, ostream uninitialized, use
	init to initialize just once. Add protected ctor that does not
	call init

Index: include/bits/basic_ios.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/basic_ios.h,v
retrieving revision 1.18
diff -c -p -r1.18 basic_ios.h
*** include/bits/basic_ios.h	9 Mar 2003 04:19:52 -0000	1.18
--- include/bits/basic_ios.h	28 Mar 2003 18:30:53 -0000
*************** namespace std 
*** 419,425 ****
         *  The default constructor does nothing and is not normally
         *  accessible to users.
        */
!       basic_ios() : ios_base() 
        { }
  
        /**
--- 419,425 ----
         *  The default constructor does nothing and is not normally
         *  accessible to users.
        */
!       basic_ios() : ios_base(), _M_fctype(0), _M_fnumput(0), _M_fnumget(0)
        { }
  
        /**
Index: include/std/std_fstream.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_fstream.h,v
retrieving revision 1.23
diff -c -p -r1.23 std_fstream.h
*** include/std/std_fstream.h	9 Mar 2003 22:31:45 -0000	1.23
--- include/std/std_fstream.h	28 Mar 2003 18:30:55 -0000
*************** namespace std
*** 525,532 ****
         *  @c &sb to the base class initializer.  Does not open any files
         *  (you haven't given it a filename to open).
        */
!       basic_ifstream()
!       : __istream_type(NULL), _M_filebuf()
        { this->init(&_M_filebuf); }
  
        /**
--- 525,531 ----
         *  @c &sb to the base class initializer.  Does not open any files
         *  (you haven't given it a filename to open).
        */
!       basic_ifstream() : __istream_type(), _M_filebuf()
        { this->init(&_M_filebuf); }
  
        /**
*************** namespace std
*** 541,547 ****
        */
        explicit
        basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
!       : __istream_type(NULL), _M_filebuf()
        {
  	this->init(&_M_filebuf);
  	this->open(__s, __mode);
--- 540,546 ----
        */
        explicit
        basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
!       : __istream_type(), _M_filebuf()
        {
  	this->init(&_M_filebuf);
  	this->open(__s, __mode);
*************** namespace std
*** 648,655 ****
         *  @c &sb to the base class initializer.  Does not open any files
         *  (you haven't given it a filename to open).
        */
!       basic_ofstream()
!       : __ostream_type(NULL), _M_filebuf()
        { this->init(&_M_filebuf); }
  
        /**
--- 647,653 ----
         *  @c &sb to the base class initializer.  Does not open any files
         *  (you haven't given it a filename to open).
        */
!       basic_ofstream(): __ostream_type(), _M_filebuf()
        { this->init(&_M_filebuf); }
  
        /**
*************** namespace std
*** 666,672 ****
        explicit
        basic_ofstream(const char* __s,
  		     ios_base::openmode __mode = ios_base::out|ios_base::trunc)
!       : __ostream_type(NULL), _M_filebuf()
        {
  	this->init(&_M_filebuf);
  	this->open(__s, __mode);
--- 664,670 ----
        explicit
        basic_ofstream(const char* __s,
  		     ios_base::openmode __mode = ios_base::out|ios_base::trunc)
!       : __ostream_type(), _M_filebuf()
        {
  	this->init(&_M_filebuf);
  	this->open(__s, __mode);
*************** namespace std
*** 776,782 ****
         *  (you haven't given it a filename to open).
        */
        basic_fstream()
!       : __iostream_type(NULL), _M_filebuf()
        { this->init(&_M_filebuf); }
  
        /**
--- 774,780 ----
         *  (you haven't given it a filename to open).
        */
        basic_fstream()
!       : __iostream_type(), _M_filebuf()
        { this->init(&_M_filebuf); }
  
        /**
Index: include/std/std_istream.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_istream.h,v
retrieving revision 1.7
diff -c -p -r1.7 std_istream.h
*** include/std/std_istream.h	9 Mar 2003 04:19:52 -0000	1.7
--- include/std/std_istream.h	28 Mar 2003 18:30:56 -0000
***************
*** 1,6 ****
  // Input streams -*- C++ -*-
  
! // Copyright (C) 1997, 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
  // software; you can redistribute it and/or modify it under the
--- 1,7 ----
  // Input streams -*- C++ -*-
  
! // Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003
! // Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
  // software; you can redistribute it and/or modify it under the
*************** namespace std
*** 101,111 ****
         *  their own stream buffer.
        */
        explicit 
!       basic_istream(__streambuf_type* __sb)
!       { 
! 	this->init(__sb);
! 	_M_gcount = streamsize(0);
!       }
  
        /**
         *  @brief  Base destructor.
--- 102,109 ----
         *  their own stream buffer.
        */
        explicit 
!       basic_istream(__streambuf_type* __sb): _M_gcount(streamsize(0))
!       { this->init(__sb); }
  
        /**
         *  @brief  Base destructor.
*************** namespace std
*** 573,578 ****
--- 571,580 ----
        __istream_type& 
        seekg(off_type, ios_base::seekdir);
        //@}
+ 
+     protected:
+       explicit 
+       basic_istream(): _M_gcount(streamsize(0)) { }
      };
    
    /**
*************** namespace std
*** 738,751 ****
        */
        explicit 
        basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
!       : __istream_type(__sb), __ostream_type(__sb)
!       { }
  
        /**
         *  @brief  Destructor does nothing.
        */
        virtual 
        ~basic_iostream() { }
      };
  
    // [27.6.1.4] standard basic_istream manipulators
--- 740,758 ----
        */
        explicit 
        basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
!       : __istream_type(), __ostream_type()
!       { this->init(__sb); }
  
        /**
         *  @brief  Destructor does nothing.
        */
        virtual 
        ~basic_iostream() { }
+ 
+     protected:
+       explicit 
+       basic_iostream() : __istream_type(), __ostream_type()
+       { }
      };
  
    // [27.6.1.4] standard basic_istream manipulators
Index: include/std/std_ostream.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_ostream.h,v
retrieving revision 1.8
diff -c -p -r1.8 std_ostream.h
*** include/std/std_ostream.h	9 Mar 2003 04:19:52 -0000	1.8
--- include/std/std_ostream.h	28 Mar 2003 18:30:56 -0000
*************** namespace std
*** 355,360 ****
--- 355,364 ----
        */
         __ostream_type& 
        seekp(off_type, ios_base::seekdir);
+       
+     protected:
+       explicit 
+       basic_ostream() { }
      };
  
    /**
Index: include/std/std_sstream.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_sstream.h,v
retrieving revision 1.15
diff -c -p -r1.15 std_sstream.h
*** include/std/std_sstream.h	24 Feb 2003 18:22:57 -0000	1.15
--- include/std/std_sstream.h	28 Mar 2003 18:30:57 -0000
*************** namespace std
*** 326,332 ****
        */
        explicit
        basic_istringstream(ios_base::openmode __mode = ios_base::in)
!       : __istream_type(NULL), _M_stringbuf(__mode | ios_base::in)
        { this->init(&_M_stringbuf); }
  
        /**
--- 326,332 ----
        */
        explicit
        basic_istringstream(ios_base::openmode __mode = ios_base::in)
!       : __istream_type(), _M_stringbuf(__mode | ios_base::in)
        { this->init(&_M_stringbuf); }
  
        /**
*************** namespace std
*** 347,353 ****
        explicit
        basic_istringstream(const __string_type& __str,
  			  ios_base::openmode __mode = ios_base::in)
!       : __istream_type(NULL), _M_stringbuf(__str, __mode | ios_base::in)
        { this->init(&_M_stringbuf); }
  
        /**
--- 347,353 ----
        explicit
        basic_istringstream(const __string_type& __str,
  			  ios_base::openmode __mode = ios_base::in)
!       : __istream_type(), _M_stringbuf(__str, __mode | ios_base::in)
        { this->init(&_M_stringbuf); }
  
        /**
*************** namespace std
*** 445,451 ****
        */
        explicit
        basic_ostringstream(ios_base::openmode __mode = ios_base::out)
!       : __ostream_type(NULL), _M_stringbuf(__mode | ios_base::out)
        { this->init(&_M_stringbuf); }
  
        /**
--- 445,451 ----
        */
        explicit
        basic_ostringstream(ios_base::openmode __mode = ios_base::out)
!       : __ostream_type(), _M_stringbuf(__mode | ios_base::out)
        { this->init(&_M_stringbuf); }
  
        /**
*************** namespace std
*** 466,472 ****
        explicit
        basic_ostringstream(const __string_type& __str,
  			  ios_base::openmode __mode = ios_base::out)
!       : __ostream_type(NULL), _M_stringbuf(__str, __mode | ios_base::out)
        { this->init(&_M_stringbuf); }
  
        /**
--- 466,472 ----
        explicit
        basic_ostringstream(const __string_type& __str,
  			  ios_base::openmode __mode = ios_base::out)
!       : __ostream_type(), _M_stringbuf(__str, __mode | ios_base::out)
        { this->init(&_M_stringbuf); }
  
        /**
*************** namespace std
*** 562,568 ****
        */
        explicit
        basic_stringstream(ios_base::openmode __m = ios_base::out | ios_base::in)
!       : __iostream_type(NULL), _M_stringbuf(__m)
        { this->init(&_M_stringbuf); }
  
        /**
--- 562,568 ----
        */
        explicit
        basic_stringstream(ios_base::openmode __m = ios_base::out | ios_base::in)
!       : __iostream_type(), _M_stringbuf(__m)
        { this->init(&_M_stringbuf); }
  
        /**
*************** namespace std
*** 581,587 ****
        explicit
        basic_stringstream(const __string_type& __str,
  			 ios_base::openmode __m = ios_base::out | ios_base::in)
!       : __iostream_type(NULL), _M_stringbuf(__str, __m)
        { this->init(&_M_stringbuf); }
  
        /**
--- 581,587 ----
        explicit
        basic_stringstream(const __string_type& __str,
  			 ios_base::openmode __m = ios_base::out | ios_base::in)
!       : __iostream_type(), _M_stringbuf(__str, __m)
        { this->init(&_M_stringbuf); }
  
        /**


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