From 5ea5d31f6d090becc33c236d91b6dd48a5d66e34 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 9 Aug 2013 16:25:43 +0000 Subject: [PATCH] Partial implementation of N3665. This paper was not voted into the C++1y draft. However I was looking at it and with some experimentation realized that I could partially implement it, and at the same time offer a performance optimization to cout. I simply added an xsputn override to the cout filebuf. The override does nothing special at all if there is a non-trivial codecvt installed. However if the codecvt returns true for always_noconv(), then this function can dump an entire string to fwrite, instead of doing it a character at a time under overflow(). This just makes sense. I stopped short of a full implementation of N3665 because in order to do so, xsputn would have to allocate a buffer when always_noconv() returned false, and I don't want to go to that expense. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@188077 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/__std_stream | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/__std_stream b/include/__std_stream index cff43317..5403adab 100644 --- a/include/__std_stream +++ b/include/__std_stream @@ -233,6 +233,7 @@ public: protected: virtual int_type overflow (int_type __c = traits_type::eof()); + virtual streamsize xsputn(const char_type* __s, streamsize __n); virtual int sync(); virtual void imbue(const locale& __loc); @@ -308,6 +309,19 @@ __stdoutbuf<_CharT>::overflow(int_type __c) return traits_type::not_eof(__c); } +template +streamsize +__stdoutbuf<_CharT>::xsputn(const char_type* __s, streamsize __n) +{ + if (__always_noconv_) + return fwrite(__s, sizeof(char_type), __n, __file_); + streamsize __i = 0; + for (; __i < __n; ++__i, ++__s) + if (overflow(traits_type::to_int_type(*__s)) == traits_type::eof()) + break; + return __i; +} + template int __stdoutbuf<_CharT>::sync()