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]

PATCH for libstdc++/2211 (some discussion held on gcc-bugs)


This patch removes an old hack that was impeding performance when C++
IO is unsynchronized from C IO (actually, it further refines where the
input buffer size of cin must be constrained to a size of 1 byte and
documents that condition).  Bootstrapped and checked on
i386-unknown-freebsd4.2.  Approved by Benjamin.  Applied to mainline
only since it only improves performance.

2001-07-02  Loren J. Rittle  <ljrittle@acm.org>

	libstdc++/2211
	* src/ios.cc (ios_base::Init::_S_ios_create): Rename __bufsize to
	__out_bufsize.  Add __in_bufsize, document it and use it.  

Index: libstdc++-v3/src/ios.cc
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/src/ios.cc,v
retrieving revision 1.19
diff -c -r1.19 ios.cc
*** ios.cc	2001/06/06 01:31:58	1.19
--- ios.cc	2001/07/02 20:41:25
***************
*** 144,157 ****
    void
    ios_base::Init::_S_ios_create(bool __sync)
    {
!     int __bufsize = __sync ? 0 : static_cast<int>(BUFSIZ);
  
      // NB: The file globals.cc creates the four standard files
      // with NULL buffers. At this point, we swap out the dummy NULL
      // [io]stream objects and buffers with the real deal.
!     new (&buf_cout) filebuf(stdout, ios_base::out, __bufsize);
!     new (&buf_cin) filebuf(stdin, ios_base::in, 1);
!     new (&buf_cerr) filebuf(stderr, ios_base::out, __bufsize);
      new (&cout) ostream(&buf_cout);
      new (&cin) istream(&buf_cin);
      new (&cerr) ostream(&buf_cerr);
--- 144,166 ----
    void
    ios_base::Init::_S_ios_create(bool __sync)
    {
!     int __out_bufsize = __sync ? 0 : static_cast<int>(BUFSIZ);
!     int __in_bufsize = __sync ? 1 : static_cast<int>(BUFSIZ);
  
+ #if _GLIBCPP_AVOID_FSEEK
+     // Platforms that prefer to avoid fseek() calls on streams only
+     // get their desire when the C++-layer input buffer size is 1.
+     // This hack hurts performance but keeps correctness across
+     // all types of streams that might be attached to (e.g.) cin.
+     __in_bufsize = 1;
+ #endif
+ 
      // NB: The file globals.cc creates the four standard files
      // with NULL buffers. At this point, we swap out the dummy NULL
      // [io]stream objects and buffers with the real deal.
!     new (&buf_cout) filebuf(stdout, ios_base::out, __out_bufsize);
!     new (&buf_cin) filebuf(stdin, ios_base::in, __in_bufsize);
!     new (&buf_cerr) filebuf(stderr, ios_base::out, __out_bufsize);
      new (&cout) ostream(&buf_cout);
      new (&cin) istream(&buf_cin);
      new (&cerr) ostream(&buf_cerr);
***************
*** 160,168 ****
      cerr.flags(ios_base::unitbuf);
      
  #ifdef _GLIBCPP_USE_WCHAR_T
!     new (&buf_wcout) wfilebuf(stdout, ios_base::out, __bufsize);
!     new (&buf_wcin) wfilebuf(stdin, ios_base::in, 1);
!     new (&buf_wcerr) wfilebuf(stderr, ios_base::out, __bufsize);
      new (&wcout) wostream(&buf_wcout);
      new (&wcin) wistream(&buf_wcin);
      new (&wcerr) wostream(&buf_wcerr);
--- 169,177 ----
      cerr.flags(ios_base::unitbuf);
      
  #ifdef _GLIBCPP_USE_WCHAR_T
!     new (&buf_wcout) wfilebuf(stdout, ios_base::out, __out_bufsize);
!     new (&buf_wcin) wfilebuf(stdin, ios_base::in, __in_bufsize);
!     new (&buf_wcerr) wfilebuf(stderr, ios_base::out, __out_bufsize);
      new (&wcout) wostream(&buf_wcout);
      new (&wcin) wistream(&buf_wcin);
      new (&wcerr) wostream(&buf_wcerr);


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