Use Slice == instead of std::memcmp if possible.

GitOrigin-RevId: fc40339f1fa51ad2995f875b5a855bfebfb87b06
This commit is contained in:
levlam 2019-07-27 01:42:18 +03:00
parent f432abcce4
commit 126be85b0f
3 changed files with 6 additions and 6 deletions

View File

@ -160,11 +160,11 @@ class Parser {
return status_; return status_;
} }
bool start_with(Slice prefix) { bool start_with(Slice prefix) const {
if (prefix.size() + ptr_ > end_) { if (prefix.size() > static_cast<size_t>(end_ - ptr_)) {
return false; return false;
} }
return std::memcmp(prefix.begin(), ptr_, prefix.size()) == 0; return prefix == Slice(ptr_, prefix.size());
} }
bool skip_start_with(Slice prefix) { bool skip_start_with(Slice prefix) {

View File

@ -48,7 +48,7 @@ struct UInt {
template <size_t size> template <size_t size>
bool operator==(const UInt<size> &a, const UInt<size> &b) { bool operator==(const UInt<size> &a, const UInt<size> &b) {
return std::memcmp(a.raw, b.raw, sizeof(a.raw)) == 0; return a.as_slice() == b.as_slice();
} }
template <size_t size> template <size_t size>
@ -84,7 +84,7 @@ MutableSlice as_slice(UInt<size> &value) {
template <size_t size> template <size_t size>
bool operator<(const UInt<size> &a, const UInt<size> &b) { bool operator<(const UInt<size> &a, const UInt<size> &b) {
return std::memcmp(a.raw, b.raw, sizeof(a.raw)) < 0; return a.as_slice() < b.as_slice();
} }
using UInt128 = UInt<128>; using UInt128 = UInt<128>;

View File

@ -24,7 +24,7 @@ bool find_boundary(ChainBufferReader range, Slice boundary, size_t &already_read
auto save_range = range.clone(); auto save_range = range.clone();
char x[MAX_BOUNDARY_LENGTH + 4]; char x[MAX_BOUNDARY_LENGTH + 4];
range.advance(boundary.size(), {x, sizeof(x)}); range.advance(boundary.size(), {x, sizeof(x)});
if (std::memcmp(x, boundary.data(), boundary.size()) == 0) { if (Slice(x, boundary.size()) == boundary) {
return true; return true;
} }