zero copy compare

pull/1994/head
Jeff Becker 2 years ago
parent a8c0f76e1c
commit bf2488d9e8
No known key found for this signature in database
GPG Key ID: 025C02EE3A092F2D

@ -123,24 +123,15 @@ llarp_buffer_t::copy() const
std::vector<byte_t> 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<const byte_t*>(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<const char*>(buff.cur), buff.size_left()} == data;
}
namespace llarp
{
OwnedBuffer

@ -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 <typename OutputIt>
bool

Loading…
Cancel
Save