summaryrefslogtreecommitdiff
path: root/absl/hash
diff options
context:
space:
mode:
authorGravatar Copybara-Service <copybara-worker@google.com>2023-02-22 08:13:06 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2023-02-22 08:13:06 -0800
commitd6ea4df62db59dc1ebc1fd3b62146700640ef400 (patch)
treea65ea233272b101048e405748df0ba892da4084e /absl/hash
parentc3b5022604551a045e383c68071d7be0a807839d (diff)
parent32794f0a4272bd4cc7ee5306999e9ff4180278d9 (diff)
Merge pull request #1388 from miladfarca:fix-Read1To3-on-BE
PiperOrigin-RevId: 511499093 Change-Id: I9ea2bbc38cbe8bd9dae937626d8faac41c010b38
Diffstat (limited to 'absl/hash')
-rw-r--r--absl/hash/internal/hash.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/absl/hash/internal/hash.h b/absl/hash/internal/hash.h
index 89740dab..61970e0d 100644
--- a/absl/hash/internal/hash.h
+++ b/absl/hash/internal/hash.h
@@ -1074,6 +1074,7 @@ class ABSL_DLL MixingHashState : public HashStateBase<MixingHashState> {
// Reads 1 to 3 bytes from p. Zero pads to fill uint32_t.
static uint32_t Read1To3(const unsigned char* p, size_t len) {
+ // The trick used by this implementation is to avoid branches if possible.
unsigned char mem0 = p[0];
unsigned char mem1 = p[len / 2];
unsigned char mem2 = p[len - 1];
@@ -1083,7 +1084,7 @@ class ABSL_DLL MixingHashState : public HashStateBase<MixingHashState> {
unsigned char significant0 = mem0;
#else
unsigned char significant2 = mem0;
- unsigned char significant1 = mem1;
+ unsigned char significant1 = len == 2 ? mem0 : mem1;
unsigned char significant0 = mem2;
#endif
return static_cast<uint32_t>(significant0 | //