summaryrefslogtreecommitdiffstats
path: root/src/common/buffer.cc
diff options
context:
space:
mode:
authorRadoslaw Zarzynski <rzarzyns@redhat.com>2021-07-19 15:55:18 +0200
committerRadoslaw Zarzynski <rzarzyns@redhat.com>2021-07-20 16:29:34 +0200
commitedf3bbc004409098b9bb3ec7a369a99b51cb131a (patch)
tree4030f5a5eeff14bd97bd4965a2907a3dfd6f75ed /src/common/buffer.cc
parentMerge pull request #42334 from tchaikov/wip-crimson-logging (diff)
downloadceph-edf3bbc004409098b9bb3ec7a369a99b51cb131a.tar.xz
ceph-edf3bbc004409098b9bb3ec7a369a99b51cb131a.zip
common/bl: c_str() examines length instead of no. of bptrs.
This approach has 2 adventages: * it takes into consideration the specical case of a bufferlist that carries solely empty bptrs while * allowing compilers to optimize-out the load-and-check of `_len` we already do in `rebuild()` which is called by `c_str()`. ```cpp void buffer::list::rebuild() { if (_len == 0) { _carriage = &always_empty_bptr; _buffers.clear_and_dispose(); _num = 0; return; } // ... } ``` Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
Diffstat (limited to 'src/common/buffer.cc')
-rw-r--r--src/common/buffer.cc17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/common/buffer.cc b/src/common/buffer.cc
index a4df5e754b0..8ade26dc911 100644
--- a/src/common/buffer.cc
+++ b/src/common/buffer.cc
@@ -1523,16 +1523,15 @@ static ceph::spinlock debug_lock;
*/
char *buffer::list::c_str()
{
- switch (get_num_buffers()) {
- case 0:
- // no buffers
- return nullptr;
- case 1:
- // good, we're already contiguous.
- break;
- default:
+ if (length() == 0) {
+ return nullptr; // no non-empty buffers
+ }
+
+ auto iter = std::cbegin(_buffers);
+ ++iter;
+
+ if (iter != std::cend(_buffers)) {
rebuild();
- break;
}
return _buffers.front().c_str();
}