]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: add bl::contents_equal() override for void* + size_t.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 16 Aug 2019 10:09:31 +0000 (06:09 -0400)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 16 Aug 2019 14:58:55 +0000 (10:58 -0400)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/common/buffer.cc
src/include/buffer.h

index d89a9817ecd9a964a5ce29b9096c59b9459c3aac..b7d3591600a5000cbc19349d6201bb26d87c0c60 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include <atomic>
+#include <cstring>
 #include <errno.h>
 #include <limits.h>
 
@@ -1003,6 +1004,27 @@ static ceph::spinlock debug_lock;
     }
   }
 
+  bool buffer::list::contents_equal(const void* const other,
+                                    size_t length) const
+  {
+    if (this->length() != length) {
+      return false;
+    }
+
+    const auto* other_buf = reinterpret_cast<const char*>(other);
+    for (const auto& bp : buffers()) {
+      const auto round_length = std::min<size_t>(length, bp.length());
+      if (std::memcmp(bp.c_str(), other_buf, round_length) != 0) {
+        return false;
+      } else {
+        length -= round_length;
+        other_buf += round_length;
+      }
+    }
+
+    return true;
+  }
+
   bool buffer::list::is_provided_buffer(const char* const dst) const
   {
     if (_buffers.empty()) {
index 642fce0a857dcf35a8ee524a21fe0fbbb30e7a5e..98358e450f647e5e3192947c10b55d22174a446b 100644 (file)
@@ -1038,6 +1038,7 @@ inline namespace v14_2_0 {
     }
 
     bool contents_equal(const buffer::list& other) const;
+    bool contents_equal(const void* other, size_t length) const;
 
     bool is_provided_buffer(const char *dst) const;
     bool is_aligned(unsigned align) const;