]> git.apps.os.sepia.ceph.com Git - ceph.git/commit
common/StackStringStream: optimize xsputn() and overflow() 25814/head
authorKefu Chai <kchai@redhat.com>
Mon, 7 Jan 2019 13:45:08 +0000 (21:45 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 9 Jan 2019 14:15:12 +0000 (22:15 +0800)
commit8d3df9be0949fb5bc9f84af563c0d3501c2fc42f
tree39a06d2a0fbc40dc9915a73eca93efcfd0c6a031
parentfa24a0312fc91c7422b130408a6bb21095ace6c3
common/StackStringStream: optimize xsputn() and overflow()

use the internal buffer semantics provided by
basic_streambuf, in hope to improve the performance when a single
character is inserted into buf.

* xsputn(): use memcpy() directly instead of creating a temporary
  string_view
* overflow(): overflow() should be called only if the internal buffer
  overflows when a single character is put into the streambuf. so
  we can use the fact that the size of inserted buffer is known,
  and use push_back() instead.
  also, please see libstdc++'s implementation of basic_streambuf::sputc(),
  where __builtin_expect() is used to instruct the compiler that
  the non-overflow branch is more likely to be chosen. so, we need
  to optimize for that branch. hence this change.
* remove the no-more-used push() method

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/StackStringStream.h