Commit 40b731de authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

Reland "[strings] Fix hash for exactly 512MB long strings"

This is a reland of 556f44c4

Original change's description:
> [strings] Fix hash for exactly 512MB long strings
> 
> Bug: chromium:1016237
> Change-Id: Idda1e44b5d578d1213aa54927ca68289bcdce8ac
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1878487
> Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
> Reviewed-by: Igor Sheludko <ishell@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#64552}

Bug: chromium:1016237
Change-Id: I92ff4da0b25877faddfd171105b77680f9e08037
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1918251Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65019}
parent db18e495
...@@ -33,9 +33,18 @@ uint32_t StringHasher::GetHashCore(uint32_t running_hash) { ...@@ -33,9 +33,18 @@ uint32_t StringHasher::GetHashCore(uint32_t running_hash) {
uint32_t StringHasher::GetTrivialHash(int length) { uint32_t StringHasher::GetTrivialHash(int length) {
DCHECK_GT(length, String::kMaxHashCalcLength); DCHECK_GT(length, String::kMaxHashCalcLength);
// String hash of a large string is simply the length. // The hash of a large string is simply computed from the length. We don't
return (static_cast<uint32_t>(length) << String::kHashShift) | // have quite enough bits, so we drop the least significant bit.
String::kIsNotArrayIndexMask | String::kIsNotIntegerIndexMask; // TODO(9904): Free up one bit, so we don't have to drop anything here.
constexpr int kDroppedBits = 1;
// Ensure that the max length after dropping bits is small enough to be
// shifted without losing information.
STATIC_ASSERT(base::bits::CountLeadingZeros32(String::kMaxLength) +
kDroppedBits >=
String::kHashShift);
uint32_t hash = static_cast<uint32_t>(length) >> kDroppedBits;
return (hash << String::kHashShift) | String::kIsNotArrayIndexMask |
String::kIsNotIntegerIndexMask;
} }
template <typename schar> template <typename schar>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment