Commit 4695abca authored by dcarney's avatar dcarney Committed by Commit bot

Don't use ConsStringIterator to compute string hashes

R=yangguo@chromium.org

BUG=

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

Cr-Commit-Position: refs/heads/master@{#25518}
parent 55614cfe
......@@ -6787,13 +6787,8 @@ uint32_t IteratingStringHasher::Hash(String* string, uint32_t seed) {
// Nothing to do.
if (hasher.has_trivial_hash()) return hasher.GetHashField();
ConsString* cons_string = String::VisitFlat(&hasher, string);
// The string was flat.
if (cons_string == NULL) return hasher.GetHashField();
// This is a ConsString, iterate across it.
ConsStringIterator iter(cons_string);
int offset;
while (NULL != (string = iter.Next(&offset))) {
String::VisitFlat(&hasher, string, offset);
if (cons_string != nullptr) {
hasher.VisitConsString(cons_string);
}
return hasher.GetHashField();
}
......
......@@ -9283,6 +9283,23 @@ uint32_t StringHasher::ComputeUtf8Hash(Vector<const char> chars,
}
void IteratingStringHasher::VisitConsString(ConsString* cons_string) {
const int max_length = String::kMaxHashCalcLength;
int length = std::min(cons_string->length(), max_length);
if (cons_string->HasOnlyOneByteChars()) {
uint8_t* buffer = new uint8_t[length];
String::WriteToFlat(cons_string, buffer, 0, length);
AddCharacters(buffer, length);
delete[] buffer;
} else {
uint16_t* buffer = new uint16_t[length];
String::WriteToFlat(cons_string, buffer, 0, length);
AddCharacters(buffer, length);
delete[] buffer;
}
}
void String::PrintOn(FILE* file) {
int length = this->length();
for (int i = 0; i < length; i++) {
......
......@@ -850,6 +850,7 @@ class AccessorPair;
class AllocationSite;
class AllocationSiteCreationContext;
class AllocationSiteUsageContext;
class ConsString;
class DictionaryElementsAccessor;
class ElementsAccessor;
class FixedArrayBase;
......@@ -8524,6 +8525,7 @@ class IteratingStringHasher : public StringHasher {
private:
inline IteratingStringHasher(int len, uint32_t seed)
: StringHasher(len, seed) {}
void VisitConsString(ConsString* cons_string);
DISALLOW_COPY_AND_ASSIGN(IteratingStringHasher);
};
......
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