From: Piotr Dałek Date: Thu, 16 Jul 2015 08:22:51 +0000 (+0200) Subject: buffer.cc: short-circuit in append for single char X-Git-Tag: v9.1.0~333^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=472f73229e97efde43ea60da4ce47ed3ad8c209b;p=ceph.git buffer.cc: short-circuit in append for single char This increases performance of function by around 20-40% by reducing call count during single-char appends. Signed-off-by: Piotr Dałek --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 90756d36364e..2bf68934e03d 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -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) { diff --git a/src/include/buffer.h b/src/include/buffer.h index 70f00180b0c1..ad72d6a11ba6 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -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();