aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@unitus.it>2003-07-04 18:15:15 +0200
committerPaolo Carlini <paolo@gcc.gnu.org>2003-07-04 16:15:15 +0000
commitac2c48d70fd44b51642ab5d2b88e1487ca11bb4f (patch)
tree48dabf186899bdf1870541b589413402ac17b03f
parentbcd5d841fe3364d90c7a2f33ccc7a32e26e3b812 (diff)
downloadgcc-ac2c48d70fd44b51642ab5d2b88e1487ca11bb4f.zip
gcc-ac2c48d70fd44b51642ab5d2b88e1487ca11bb4f.tar.gz
gcc-ac2c48d70fd44b51642ab5d2b88e1487ca11bb4f.tar.bz2
re PR libstdc++/11378 (Unbuffered sputn is slow)
2003-07-04 Paolo Carlini <pcarlini@unitus.it> PR libstdc++/11378 * include/std/std_fstream.h (xsputn): In the unbuffered case, provided always_noconv(), issue directly _M_file.xsputn. * testsuite/performance/filebuf_unbuf_sputn.cc: New. From-SVN: r68921
-rw-r--r--libstdc++-v3/ChangeLog7
-rw-r--r--libstdc++-v3/include/std/std_fstream.h18
-rw-r--r--libstdc++-v3/testsuite/performance/filebuf_unbuf_sputn.cc130
3 files changed, 152 insertions, 3 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index f5a7826..c923998 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,12 @@
2003-07-04 Paolo Carlini <pcarlini@unitus.it>
+ PR libstdc++/11378
+ * include/std/std_fstream.h (xsputn): In the unbuffered case,
+ provided always_noconv(), issue directly _M_file.xsputn.
+ * testsuite/performance/filebuf_unbuf_sputn.cc: New.
+
+2003-07-04 Paolo Carlini <pcarlini@unitus.it>
+
* include/bits/stl_list.h: Fully qualify standard
functions with std::, thus avoiding Koenig lookup.
* include/bits/stl_queue.h: Likewise.
diff --git a/libstdc++-v3/include/std/std_fstream.h b/libstdc++-v3/include/std/std_fstream.h
index b97c944..7660235 100644
--- a/libstdc++-v3/include/std/std_fstream.h
+++ b/libstdc++-v3/include/std/std_fstream.h
@@ -397,9 +397,21 @@ namespace std
virtual streamsize
xsputn(const char_type* __s, streamsize __n)
{
- _M_destroy_pback();
- return __streambuf_type::xsputn(__s, __n);
- }
+ streamsize __ret = 0;
+
+ const bool __testout = this->_M_mode & ios_base::out;
+ if (__testout && !_M_reading && this->_M_buf_size == 1
+ && __check_facet(_M_codecvt).always_noconv())
+ {
+ __ret = _M_file.xsputn(reinterpret_cast<const char*>(__s), __n);
+ if (__ret == __n)
+ _M_writing = true;
+ }
+ else
+ __ret = __streambuf_type::xsputn(__s, __n);
+
+ return __ret;
+ }
/**
* @if maint
diff --git a/libstdc++-v3/testsuite/performance/filebuf_unbuf_sputn.cc b/libstdc++-v3/testsuite/performance/filebuf_unbuf_sputn.cc
new file mode 100644
index 0000000..17b0c46
--- /dev/null
+++ b/libstdc++-v3/testsuite/performance/filebuf_unbuf_sputn.cc
@@ -0,0 +1,130 @@
+// 2003-07-04 Petur Runolfsson <peturr02@ru.is>
+//
+// Copyright (C) 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <cstdio>
+#include <cstring>
+#include <fstream>
+#include <iostream>
+
+// Contributed as part of libstdc++/11378.
+int main(int argc, char** argv)
+{
+ using namespace std;
+
+ if (argc < 3)
+ {
+ cerr << "Usage: " << argv[0] << " type iters [chunksize]\n";
+ return -1;
+ }
+
+ enum { type_stdio, type_iostream } type;
+
+ if (!strcmp(argv[1], "stdio"))
+ type = type_stdio;
+ else if (!strcmp(argv[1], "iostream"))
+ type = type_iostream;
+ else
+ {
+ cerr << "Type must be one of {stdio, iostream}\n";
+ return -1;
+ }
+
+ int iters = atoi(argv[2]);
+ if (iters < 1)
+ {
+ cerr << "Iters must be an positive integer\n";
+ return -1;
+ }
+
+ int chunksize = 1;
+ if (argc > 3)
+ chunksize = atoi(argv[3]);
+
+ if (iters < 1)
+ {
+ cerr << "Chunksize must be an positive integer\n";
+ return -1;
+ }
+
+ char* chunk = 0;
+ if (chunksize > 1)
+ {
+ chunk = new char[chunksize];
+ memset(chunk, 'a', chunksize);
+ }
+
+ switch (type)
+ {
+ case type_stdio:
+ {
+ FILE* f = fopen("tmp", "w");
+ setvbuf(f, 0, _IONBF, 0);
+
+ if (chunksize > 1)
+ {
+ for (int i = 0; i < iters; ++i)
+ fwrite_unlocked(chunk, 1, chunksize, f);
+ }
+ else
+ {
+ for (int i = 0; i < iters; ++i)
+ putc_unlocked('a', f);
+ }
+
+ fclose(f);
+ break;
+ }
+
+ case type_iostream:
+ {
+ filebuf f;
+ f.pubsetbuf(0, 0);
+
+ f.open("tmp", ios_base::out);
+
+ if (chunksize > 1)
+ {
+ for (int i = 0; i < iters; ++i)
+ f.sputn(chunk, chunksize);
+ }
+ else
+ {
+ for (int i = 0; i < iters; ++i)
+ f.sputc('a');
+ }
+
+ f.close();
+
+ break;
+ }
+ }
+
+ delete[] chunk;
+ return 0;
+}