diff --git a/llarp/util/buffer.cpp b/llarp/util/buffer.cpp index f185e6347..f02eae652 100644 --- a/llarp/util/buffer.cpp +++ b/llarp/util/buffer.cpp @@ -123,24 +123,15 @@ llarp_buffer_t::copy() const std::vector copy; copy.resize(sz); std::copy_n(base, sz, copy.data()); + return copy; } bool -operator==(const llarp_buffer_t& buff, const char* c_str) +operator==(const llarp_buffer_t& buff, std::string_view data) { - const auto* str = reinterpret_cast(c_str); - ManagedBuffer copy{buff}; - while (*str && copy.underlying.cur != (copy.underlying.base + copy.underlying.sz)) - { - if (*copy.underlying.cur != *str) - return false; - copy.underlying.cur++; - str++; - } - return *str == 0; + return std::string_view{reinterpret_cast(buff.cur), buff.size_left()} == data; } - namespace llarp { OwnedBuffer diff --git a/llarp/util/buffer.hpp b/llarp/util/buffer.hpp index 2f2ff10a6..841945d03 100644 --- a/llarp/util/buffer.hpp +++ b/llarp/util/buffer.hpp @@ -182,7 +182,7 @@ struct llarp_buffer_t }; bool -operator==(const llarp_buffer_t& buff, const char* data); +operator==(const llarp_buffer_t& buff, std::string_view data); template bool