summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHoward Hinnant <hhinnant@apple.com>2013-08-09 16:25:43 +0000
committerHoward Hinnant <hhinnant@apple.com>2013-08-09 16:25:43 +0000
commitd7cda0680a0c0f1ef402f302df22049f8062236e (patch)
treea51960bcc716cfec1c018f99edcb059a28d4c58f
parentc65848caa59147cb51e913b5e70de609f5e8a171 (diff)
downloadbcm5719-llvm-d7cda0680a0c0f1ef402f302df22049f8062236e.tar.gz
bcm5719-llvm-d7cda0680a0c0f1ef402f302df22049f8062236e.zip
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.
llvm-svn: 188077
-rw-r--r--libcxx/include/__std_stream14
1 files changed, 14 insertions, 0 deletions
diff --git a/libcxx/include/__std_stream b/libcxx/include/__std_stream
index cff43317e58..5403adabc34 100644
--- a/libcxx/include/__std_stream
+++ b/libcxx/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);
@@ -309,6 +310,19 @@ __stdoutbuf<_CharT>::overflow(int_type __c)
}
template <class _CharT>
+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 <class _CharT>
int
__stdoutbuf<_CharT>::sync()
{
OpenPOWER on IntegriCloud