add fast path for hashing small cons strings

R=yangguo@chromium.org
LOG=N

BUG=437280

Review URL: https://codereview.chromium.org/769453002

Cr-Commit-Position: refs/heads/master@{#25562}
This commit is contained in:
dcarney 2014-11-28 03:07:34 -08:00 committed by Commit bot
parent 0de87ac84e
commit 660de644ae
2 changed files with 14 additions and 3 deletions

View File

@ -6828,9 +6828,8 @@ uint32_t IteratingStringHasher::Hash(String* string, uint32_t seed) {
// Nothing to do. // Nothing to do.
if (hasher.has_trivial_hash()) return hasher.GetHashField(); if (hasher.has_trivial_hash()) return hasher.GetHashField();
ConsString* cons_string = String::VisitFlat(&hasher, string); ConsString* cons_string = String::VisitFlat(&hasher, string);
if (cons_string != nullptr) { if (cons_string == nullptr) return hasher.GetHashField();
hasher.VisitConsString(cons_string); hasher.VisitConsString(cons_string);
}
return hasher.GetHashField(); return hasher.GetHashField();
} }

View File

@ -9298,6 +9298,18 @@ uint32_t StringHasher::ComputeUtf8Hash(Vector<const char> chars,
void IteratingStringHasher::VisitConsString(ConsString* cons_string) { void IteratingStringHasher::VisitConsString(ConsString* cons_string) {
// Run small ConsStrings through ConsStringIterator.
if (cons_string->length() < 64) {
ConsStringIterator iter(cons_string);
int offset;
String* string;
while (nullptr != (string = iter.Next(&offset))) {
DCHECK_EQ(0, offset);
String::VisitFlat(this, string, 0);
}
return;
}
// Slow case.
const int max_length = String::kMaxHashCalcLength; const int max_length = String::kMaxHashCalcLength;
int length = std::min(cons_string->length(), max_length); int length = std::min(cons_string->length(), max_length);
if (cons_string->HasOnlyOneByteChars()) { if (cons_string->HasOnlyOneByteChars()) {