Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
Overloaded __pad_and_output on ostreambuf_iterator and in this overlo…
Browse files Browse the repository at this point in the history
…ad call sputn instead of dereferencing the iterator which calls sputc. This is intended to be purely a performance optimization, especially for clients who may have overloaded the virtual function xsputn.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@164241 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Howard Hinnant committed Sep 19, 2012
1 parent 7eb9f1e commit a585de6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/iterator
Expand Up @@ -881,6 +881,14 @@ public:
_LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
_LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
_LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}

template <class _Ch, class _Tr>
friend
_LIBCPP_HIDDEN
ostreambuf_iterator<_Ch, _Tr>
__pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
ios_base& __iob, _Ch __fl);
};

template <class _Iter>
Expand Down
46 changes: 46 additions & 0 deletions include/locale
Expand Up @@ -1587,6 +1587,52 @@ __pad_and_output(_OutputIterator __s,
return __s;
}

template <class _CharT, class _Traits>
_LIBCPP_HIDDEN
ostreambuf_iterator<_CharT, _Traits>
__pad_and_output(ostreambuf_iterator<_CharT, _Traits> __s,
const _CharT* __ob, const _CharT* __op, const _CharT* __oe,
ios_base& __iob, _CharT __fl)
{
if (__s.__sbuf_ == nullptr)
return __s;
streamsize __sz = __oe - __ob;
streamsize __ns = __iob.width();
if (__ns > __sz)
__ns -= __sz;
else
__ns = 0;
streamsize __np = __op - __ob;
if (__np > 0)
{
if (__s.__sbuf_->sputn(__ob, __np) != __np)
{
__s.__sbuf_ = nullptr;
return __s;
}
}
if (__ns > 0)
{
basic_string<_CharT, _Traits> __sp(__ns, __fl);
if (__s.__sbuf_->sputn(__sp.data(), __ns) != __ns)
{
__s.__sbuf_ = nullptr;
return __s;
}
}
__np = __oe - __op;
if (__np > 0)
{
if (__s.__sbuf_->sputn(__op, __np) != __np)
{
__s.__sbuf_ = nullptr;
return __s;
}
}
__iob.width(0);
return __s;
}

template <class _CharT, class _OutputIterator>
_OutputIterator
num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
Expand Down

0 comments on commit a585de6

Please sign in to comment.