]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
src/include/encoding.h: reduce amount of 0-byte appends
authorPiotr Dałek <piotr.dalek@ts.fujitsu.com>
Thu, 25 Jun 2015 12:36:41 +0000 (14:36 +0200)
committerPiotr Dałek <piotr.dalek@ts.fujitsu.com>
Tue, 4 Aug 2015 07:56:30 +0000 (09:56 +0200)
Some encoding functions (in particular, encoders for strings) right now
use two encode() calls, one for data length and one for actual data. This
change makes encoding functions aware of the data length and don't call
second encode if there's no actual data to encode - conditional branch is
faster than function call.

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

index aaa843b544da691b6635faef0981c2aca351ff3e..ab52f32d06ba0b0e5a6f374efcfe5c5491069571 100644 (file)
@@ -164,7 +164,8 @@ inline void encode(const std::string& s, bufferlist& bl, uint64_t features=0)
 {
   __u32 len = s.length();
   encode(len, bl);
-  bl.append(s.data(), len);
+  if (len)
+    bl.append(s.data(), len);
 }
 inline void decode(std::string& s, bufferlist::iterator& p)
 {
@@ -189,7 +190,8 @@ inline void encode(const char *s, bufferlist& bl)
 {
   __u32 len = strlen(s);
   encode(len, bl);
-  bl.append(s, len);
+  if (len)
+    bl.append(s, len);
 }