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}
This commit is contained in:
parent
55614cfe69
commit
4695abcafa
@ -6787,13 +6787,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);
|
||||||
// The string was flat.
|
if (cons_string != nullptr) {
|
||||||
if (cons_string == NULL) return hasher.GetHashField();
|
hasher.VisitConsString(cons_string);
|
||||||
// This is a ConsString, iterate across it.
|
|
||||||
ConsStringIterator iter(cons_string);
|
|
||||||
int offset;
|
|
||||||
while (NULL != (string = iter.Next(&offset))) {
|
|
||||||
String::VisitFlat(&hasher, string, offset);
|
|
||||||
}
|
}
|
||||||
return hasher.GetHashField();
|
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) {
|
void String::PrintOn(FILE* file) {
|
||||||
int length = this->length();
|
int length = this->length();
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
|
@ -850,6 +850,7 @@ class AccessorPair;
|
|||||||
class AllocationSite;
|
class AllocationSite;
|
||||||
class AllocationSiteCreationContext;
|
class AllocationSiteCreationContext;
|
||||||
class AllocationSiteUsageContext;
|
class AllocationSiteUsageContext;
|
||||||
|
class ConsString;
|
||||||
class DictionaryElementsAccessor;
|
class DictionaryElementsAccessor;
|
||||||
class ElementsAccessor;
|
class ElementsAccessor;
|
||||||
class FixedArrayBase;
|
class FixedArrayBase;
|
||||||
@ -8524,6 +8525,7 @@ class IteratingStringHasher : public StringHasher {
|
|||||||
private:
|
private:
|
||||||
inline IteratingStringHasher(int len, uint32_t seed)
|
inline IteratingStringHasher(int len, uint32_t seed)
|
||||||
: StringHasher(len, seed) {}
|
: StringHasher(len, seed) {}
|
||||||
|
void VisitConsString(ConsString* cons_string);
|
||||||
DISALLOW_COPY_AND_ASSIGN(IteratingStringHasher);
|
DISALLOW_COPY_AND_ASSIGN(IteratingStringHasher);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user