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)


Benjamin says that:

>          std::ios::sync_with_stdio(false)
>          will improve output performance.

I concur except the C++ IO buffer size is set "(much) less than optimally"
for most hosts even when C++ IO is to be unsynchronized with C IO.

In my opinion, only hosts that want to be able to use ungetc/getc in
place of fseek() within underflow() force a requirement that an input
buffer attached to cin be of size 1 without regard to whether we are
synchronized with C IO or not.  Hosts that have a libc that allows
fseek() on any type of stream (be they pipes or interactive), do not
care and should not be forced to use an input buffer size of 1 in the
unsynchronized case since it really kills performance.  The attached
patch matches this level of my thinking on the matter.

No testsuite regressions on i386-*-freebsd4.2 (it usually defines
_GLIBCPP_AVOID_FSEEK but I rebuilt the library and checked both ways).

Comments?  OK to install?

Index: 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/06/30 06:32:36
***************
*** 145,156 ****
    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);
--- 145,161 ----
    ios_base::Init::_S_ios_create(bool __sync)
    {
      int __bufsize = __sync ? 0 : static_cast<int>(BUFSIZ);
+     int __in_bufsize = __sync ? 1 : static_cast<int>(BUFSIZ);
  
+ #if _GLIBCPP_AVOID_FSEEK
+     __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, __bufsize);
!     new (&buf_cin) filebuf(stdin, ios_base::in, __in_bufsize);
      new (&buf_cerr) filebuf(stderr, ios_base::out, __bufsize);
      new (&cout) ostream(&buf_cout);
      new (&cin) istream(&buf_cin);
***************
*** 161,167 ****
      
  #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);
--- 166,172 ----
      
  #ifdef _GLIBCPP_USE_WCHAR_T
      new (&buf_wcout) wfilebuf(stdout, ios_base::out, __bufsize);
!     new (&buf_wcin) wfilebuf(stdin, ios_base::in, __in_bufsize);
      new (&buf_wcerr) wfilebuf(stderr, ios_base::out, __bufsize);
      new (&wcout) wostream(&buf_wcout);
      new (&wcin) wistream(&buf_wcin);


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