Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(858)

Unified Diff: src/parser.cc

Issue 765473006: Make TemplateLiteral hashing algorithm more memory efficient (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Change assertions in StringHasher extensions, add comment about hash key usage Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index c2d6c5754849a1601b23569e6b1aef8f562a255b..712fdd4f44e8d4e1fd61d6de14bac0be6f013222 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -5295,14 +5295,7 @@ ZoneList<Expression*>* Parser::TemplateRawStrings(const TemplateLiteral* lit,
raw_strings = new (zone()) ZoneList<Expression*>(total, zone());
- int num_hash_chars = (total - 1) * 3;
- for (int index = 0; index < total; ++index) {
- // Allow about length * 4 to handle most UTF8 sequences.
- num_hash_chars += lengths->at(index) * 4;
- }
-
- Vector<uint8_t> hash_string = Vector<uint8_t>::New(num_hash_chars);
- num_hash_chars = 0;
+ uint32_t running_hash = 0;
for (int index = 0; index < total; ++index) {
int span_start = cooked_strings->at(index)->position() + 1;
@@ -5311,9 +5304,8 @@ ZoneList<Expression*>* Parser::TemplateRawStrings(const TemplateLiteral* lit,
int to_index = 0;
if (index) {
- hash_string[num_hash_chars++] = '$';
- hash_string[num_hash_chars++] = '{';
- hash_string[num_hash_chars++] = '}';
+ running_hash = StringHasher::ComputeRunningHashOneByte(
+ running_hash, "${}", 3);
}
SmartArrayPointer<char> raw_chars =
@@ -5330,7 +5322,6 @@ ZoneList<Expression*>* Parser::TemplateRawStrings(const TemplateLiteral* lit,
++from_index;
}
}
- hash_string[num_hash_chars++] = ch;
raw_chars[to_index++] = ch;
}
@@ -5342,6 +5333,8 @@ ZoneList<Expression*>* Parser::TemplateRawStrings(const TemplateLiteral* lit,
if (utf16_length > 0) {
uc16* utf16_buffer = zone()->NewArray<uc16>(utf16_length);
to_index = decoder->WriteUtf16(utf16_buffer, utf16_length);
+ running_hash = StringHasher::ComputeRunningHash(
+ running_hash, utf16_buffer, to_index);
const uint16_t* data = reinterpret_cast<const uint16_t*>(utf16_buffer);
const AstRawString* raw_str = ast_value_factory()->GetTwoByteString(
Vector<const uint16_t>(data, to_index));
@@ -5354,11 +5347,10 @@ ZoneList<Expression*>* Parser::TemplateRawStrings(const TemplateLiteral* lit,
raw_strings->Add(raw_lit, zone());
}
- hash_string.Truncate(num_hash_chars);
- int utf16_length;
- *hash = StringHasher::ComputeUtf8Hash(Vector<const char>::cast(hash_string),
- num_hash_chars, &utf16_length);
- hash_string.Dispose();
+ // Hash key is used exclusively by template call site caching. There are no
+ // real security implications for unseeded hashes, and no issues with changing
+ // the hashing algorithm to improve performance or entropy.
+ *hash = running_hash;
return raw_strings;
}
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698