Skip to content

Commit

Permalink
Merge pull request ceph#15307 from ovh/bp-64bit-mem-is-zero
Browse files Browse the repository at this point in the history
inline_memory: optimized mem_is_zero for non-x64

Reviewed-by: Sage Weil <[email protected]>
  • Loading branch information
liewegas authored Jun 1, 2017
2 parents 268d5cd + 9b5a1a4 commit 703125e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/include/inline_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ bool mem_is_zero(const char *data, size_t len)

static inline bool mem_is_zero(const char *data, size_t len) {
const char *end = data + len;
const char* end64 = data + (len / sizeof(uint64_t))*sizeof(uint64_t);

while (data < end64) {
if (*(uint64_t*)data != 0) {
return false;
}
data += sizeof(uint64_t);
}

while (data < end) {
if (*data != 0) {
return false;
Expand Down
11 changes: 11 additions & 0 deletions src/test/bufferlist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,17 @@ TEST(BufferList, is_zero) {
bl.append_zero(1);
EXPECT_TRUE(bl.is_zero());
}

for (size_t i = 1; i <= 256; ++i) {
bufferlist bl;
bl.append_zero(i);
EXPECT_TRUE(bl.is_zero());
bl.append('A');
// ensure buffer is a single, contiguous before testing
bl.rebuild();
EXPECT_FALSE(bl.is_zero());
}

}

TEST(BufferList, clear) {
Expand Down

0 comments on commit 703125e

Please sign in to comment.