]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
buffer.cc: short-circuit in append for single char
authorPiotr Dałek <piotr.dalek@ts.fujitsu.com>
Thu, 16 Jul 2015 08:22:51 +0000 (10:22 +0200)
committerPiotr Dałek <piotr.dalek@ts.fujitsu.com>
Tue, 4 Aug 2015 07:59:04 +0000 (09:59 +0200)
This increases performance of function by around 20-40% by reducing
call count during single-char appends.

Signed-off-by: Piotr Dałek <piotr.dalek@ts.fujitsu.com>
src/common/buffer.cc
src/include/buffer.h

index 90756d36364e5f8b0f9b06510f0c3a6e6650c0e8..2bf68934e03dcb2ec3e52a31903cd0a94102008d 100644 (file)
@@ -882,14 +882,16 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
     return true;
   }
 
-  void buffer::ptr::append(char c)
+  unsigned buffer::ptr::append(char c)
   {
     assert(_raw);
     assert(1 <= unused_tail_length());
-    (c_str())[_len] = c;
+    char* ptr = _raw->data + _off + _len;
+    *ptr = c;
     _len++;
+    return _len + _off;
   }
-  
+
   unsigned buffer::ptr::append(const char *p, unsigned l)
   {
     assert(_raw);
@@ -1487,10 +1489,9 @@ void buffer::list::rebuild_page_aligned()
       append_buffer = create_page_aligned(alen);
       append_buffer.set_length(0);   // unused, so far.
     }
-    append_buffer.append(c);
-    append(append_buffer, append_buffer.end() - 1, 1); // add segment to the list
+    append(append_buffer, append_buffer.append(c) - 1, 1);     // add segment to the list
   }
-  
+
   void buffer::list::append(const char *data, unsigned len)
   {
     while (len > 0) {
index 70f00180b0c1e3924395f560b28de25d132ac719..ad72d6a11ba6fbbe0b2cc4af859fee06ee6163cc 100644 (file)
@@ -239,7 +239,7 @@ public:
       _len = l;
     }
 
-    void append(char c);
+    unsigned append(char c);
     unsigned append(const char *p, unsigned l);
     void copy_in(unsigned o, unsigned l, const char *src);
     void zero();