]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/bl: abstract from _carriage checking in c_str().
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Thu, 5 Aug 2021 00:04:57 +0000 (00:04 +0000)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 13 Sep 2021 19:16:32 +0000 (21:16 +0200)
This is intended to enchance readability and sligthly
generalize the previous, `_carriage`-aware optimization.

Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/common/buffer.cc

index 2b534402f6dca7c8f624603fea02d2398cce94aa..1b36b0543c7504b527f6665586b9b551b2a16528 100644 (file)
@@ -1523,18 +1523,17 @@ static ceph::spinlock debug_lock;
    */
   char *buffer::list::c_str()
   {
-    if (length() == 0) {
+    if (const auto len = length(); len == 0) {
       return nullptr;                         // no non-empty buffers
-    }
-
-    const auto second = std::next(std::cbegin(_buffers));
-    // splice() tries to not waste our appendable space; to carry
-    // it an empty bptr is added at the end. we account for that.
-    const auto end = _carriage->length() == 0 && \
-      _carriage == &_buffers.back() ? buffers_t::const_iterator(_carriage)
-                                    : std::cend(_buffers);
-    if (second != end) {
+    } else if (len != _buffers.front().length()) {
       rebuild();
+    } else {
+      // there are two *main* scenarios that hit this branch:
+      //   1. bufferlist with single, non-empty buffer;
+      //   2. bufferlist with single, non-empty buffer followed by
+      //      empty buffer. splice() tries to not waste our appendable
+      //      space; to carry it an empty bptr is added at the end.
+      // we account for these and don't rebuild unnecessarily
     }
     return _buffers.front().c_str();
   }