From: Radoslaw Zarzynski Date: Fri, 16 Aug 2019 10:09:31 +0000 (-0400) Subject: common: add bl::contents_equal() override for void* + size_t. X-Git-Tag: v15.1.0~1790^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9c1bb6a055463bc500a3488add3c65076ad098a2;p=ceph.git common: add bl::contents_equal() override for void* + size_t. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index d89a9817ecd9..b7d3591600a5 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -13,6 +13,7 @@ */ #include +#include #include #include @@ -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(other); + for (const auto& bp : buffers()) { + const auto round_length = std::min(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()) { diff --git a/src/include/buffer.h b/src/include/buffer.h index 642fce0a857d..98358e450f64 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -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;