diff options
| author | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2016-02-17 15:43:38 +0900 |
|---|---|---|
| committer | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2016-02-17 15:46:14 +0900 |
| commit | 121165ed878d844662a25d5ee3b95ab1ceaddca2 (patch) | |
| tree | e56742c0b59827c1c8f089fd6da91f793cf33960 /string_piece.cc | |
| parent | 0a6e2a4e09f3863a150b060a68640b5efc99beab (diff) | |
[C++] Compare last 8 bytes first in StringPiece::operator==
Diffstat (limited to 'string_piece.cc')
| -rw-r--r-- | string_piece.cc | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/string_piece.cc b/string_piece.cc index 78de4ed..d287616 100644 --- a/string_piece.cc +++ b/string_piece.cc @@ -21,6 +21,7 @@ #include <ctype.h> #include <limits.h> +#include <stdint.h> #include <algorithm> #include <ostream> @@ -32,8 +33,15 @@ typedef StringPiece::size_type size_type; bool operator==(const StringPiece& x, const StringPiece& y) { if (x.size() != y.size()) return false; - - return StringPiece::wordmemcmp(x.data(), y.data(), x.size()) == 0; + size_t len = x.size(); + if (len >= sizeof(uint64_t)) { + len -= sizeof(uint64_t); + uint64_t xt = *reinterpret_cast<const uint64_t*>(x.data() + len); + uint64_t yt = *reinterpret_cast<const uint64_t*>(y.data() + len); + if (xt != yt) + return false; + } + return StringPiece::wordmemcmp(x.data(), y.data(), len) == 0; } void StringPiece::CopyToString(std::string* target) const { |
