From: Piotr Dałek Date: Thu, 25 Jun 2015 12:36:41 +0000 (+0200) Subject: src/include/encoding.h: reduce amount of 0-byte appends X-Git-Tag: v9.1.0~333^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2219200cb5bac1272fbee1e28d2fefecd5e657b7;p=ceph.git src/include/encoding.h: reduce amount of 0-byte appends 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 --- diff --git a/src/include/encoding.h b/src/include/encoding.h index aaa843b544da..ab52f32d06ba 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -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); }