Commit f36497d2 authored by marja's avatar marja Committed by Commit bot

AstValueFactory: add a cache for one-character strings.

Lowercase 1 character strings occur frequently in minified code. Add a
cache for them, so that we don't need to compute the hash + do the hash
table lookup for each occurrence.

BUG=

Review-Url: https://codereview.chromium.org/2541353002
Cr-Commit-Position: refs/heads/master@{#41597}
parent e8f5adbe
......@@ -28,6 +28,7 @@
#include "src/ast/ast-value-factory.h"
#include "src/api.h"
#include "src/char-predicates-inl.h"
#include "src/objects.h"
#include "src/utils.h"
......@@ -222,6 +223,15 @@ void AstValue::Internalize(Isolate* isolate) {
AstRawString* AstValueFactory::GetOneByteStringInternal(
Vector<const uint8_t> literal) {
if (literal.length() == 1 && IsInRange(literal[0], 'a', 'z')) {
int key = literal[0] - 'a';
if (one_character_strings_[key] == nullptr) {
uint32_t hash = StringHasher::HashSequentialString<uint8_t>(
literal.start(), literal.length(), hash_seed_);
one_character_strings_[key] = GetString(hash, true, literal);
}
return one_character_strings_[key];
}
uint32_t hash = StringHasher::HashSequentialString<uint8_t>(
literal.start(), literal.length(), hash_seed_);
return GetString(hash, true, literal);
......
......@@ -333,7 +333,6 @@ class AstValueFactory {
AstValueFactory(Zone* zone, uint32_t hash_seed)
: string_table_(AstRawStringCompare),
values_(nullptr),
smis_(),
strings_(nullptr),
strings_end_(&strings_),
zone_(zone),
......@@ -345,6 +344,9 @@ class AstValueFactory {
OTHER_CONSTANTS(F)
#undef F
std::fill(smis_, smis_ + arraysize(smis_), nullptr);
std::fill(one_character_strings_,
one_character_strings_ + arraysize(one_character_strings_),
nullptr);
}
Zone* zone() const { return zone_; }
......@@ -422,11 +424,16 @@ class AstValueFactory {
// they can be internalized later).
AstValue* values_;
AstValue* smis_[kMaxCachedSmi + 1];
// We need to keep track of strings_ in order since cons strings require their
// members to be internalized first.
AstString* strings_;
AstString** strings_end_;
// Caches for faster access: small numbers, one character lowercase strings
// (for minified code).
AstValue* smis_[kMaxCachedSmi + 1];
AstRawString* one_character_strings_[26];
Zone* zone_;
uint32_t hash_seed_;
......
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