mem_is_zero is fast for X64 where 128-bit registers are available,
but it's very easy to optimze it for 32-bit Intel and ARM CPUs as
well, the speed won't be anywhere near the fastest one but still almost
7x faster than regular byte-by-byte check.
Now with extra test to check for corner cases that may pop with such
implementations.
Signed-off-by: Piotr Dałek <piotr.dalek@corp.ovh.com>
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;
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) {