Commit 522bc812 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[runtime] Move virtual AsHandle from HashTableKey to StringTableKey

Bug: 
Change-Id: I9f0329b69693749c243c05b27c542c4ccdd71a11
Reviewed-on: https://chromium-review.googlesource.com/531244Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45891}
parent 1b4934b9
...@@ -55,7 +55,7 @@ class OneByteStringStream { ...@@ -55,7 +55,7 @@ class OneByteStringStream {
} // namespace } // namespace
class AstRawStringInternalizationKey : public HashTableKey { class AstRawStringInternalizationKey : public StringTableKey {
public: public:
explicit AstRawStringInternalizationKey(const AstRawString* string) explicit AstRawStringInternalizationKey(const AstRawString* string)
: string_(string) {} : string_(string) {}
......
...@@ -2669,7 +2669,8 @@ uint32_t StringSetShape::HashForObject(Object* object) { ...@@ -2669,7 +2669,8 @@ uint32_t StringSetShape::HashForObject(Object* object) {
return String::cast(object)->Hash(); return String::cast(object)->Hash();
} }
Handle<Object> StringTableShape::AsHandle(Isolate* isolate, HashTableKey* key) { Handle<Object> StringTableShape::AsHandle(Isolate* isolate,
StringTableKey* key) {
return key->AsHandle(isolate); return key->AsHandle(isolate);
} }
......
...@@ -15935,7 +15935,7 @@ class StringSharedKey : public HashTableKey { ...@@ -15935,7 +15935,7 @@ class StringSharedKey : public HashTableKey {
language_mode_, position_); language_mode_, position_);
} }
Handle<Object> AsHandle(Isolate* isolate) override { Handle<Object> AsHandle(Isolate* isolate) {
Handle<FixedArray> array = isolate->factory()->NewFixedArray(4); Handle<FixedArray> array = isolate->factory()->NewFixedArray(4);
array->set(0, *shared_); array->set(0, *shared_);
array->set(1, *source_); array->set(1, *source_);
...@@ -16173,12 +16173,6 @@ class RegExpKey : public HashTableKey { ...@@ -16173,12 +16173,6 @@ class RegExpKey : public HashTableKey {
return CompilationCacheShape::RegExpHash(*string_, flags_); return CompilationCacheShape::RegExpHash(*string_, flags_);
} }
Handle<Object> AsHandle(Isolate* isolate) override {
// Plain hash maps, which is where regexp keys are used, don't
// use this function.
UNREACHABLE();
}
Handle<String> string_; Handle<String> string_;
Smi* flags_; Smi* flags_;
}; };
...@@ -16210,7 +16204,7 @@ bool SeqOneByteSubStringKey::IsMatch(Object* string) { ...@@ -16210,7 +16204,7 @@ bool SeqOneByteSubStringKey::IsMatch(Object* string) {
// InternalizedStringKey carries a string/internalized-string object as key. // InternalizedStringKey carries a string/internalized-string object as key.
class InternalizedStringKey : public HashTableKey { class InternalizedStringKey : public StringTableKey {
public: public:
explicit InternalizedStringKey(Handle<String> string) explicit InternalizedStringKey(Handle<String> string)
: string_(String::Flatten(string)) {} : string_(String::Flatten(string)) {}
...@@ -16247,10 +16241,6 @@ class InternalizedStringKey : public HashTableKey { ...@@ -16247,10 +16241,6 @@ class InternalizedStringKey : public HashTableKey {
string_, string_->length(), string_->hash_field()); string_, string_->length(), string_->hash_field());
} }
static uint32_t StringHash(Object* obj) {
return String::cast(obj)->Hash();
}
private: private:
Handle<String> string_; Handle<String> string_;
}; };
...@@ -17157,7 +17147,7 @@ Handle<PropertyCell> JSGlobalObject::EnsureEmptyPropertyCell( ...@@ -17157,7 +17147,7 @@ Handle<PropertyCell> JSGlobalObject::EnsureEmptyPropertyCell(
// string hash calculation loop here for speed. Doesn't work if the two // string hash calculation loop here for speed. Doesn't work if the two
// characters form a decimal integer, since such strings have a different hash // characters form a decimal integer, since such strings have a different hash
// algorithm. // algorithm.
class TwoCharHashTableKey : public HashTableKey { class TwoCharHashTableKey : public StringTableKey {
public: public:
TwoCharHashTableKey(uint16_t c1, uint16_t c2, uint32_t seed) TwoCharHashTableKey(uint16_t c1, uint16_t c2, uint32_t seed)
: c1_(c1), c2_(c2) { : c1_(c1), c2_(c2) {
...@@ -17360,8 +17350,7 @@ Handle<String> StringTable::LookupString(Isolate* isolate, ...@@ -17360,8 +17350,7 @@ Handle<String> StringTable::LookupString(Isolate* isolate,
return result; return result;
} }
Handle<String> StringTable::LookupKey(Isolate* isolate, StringTableKey* key) {
Handle<String> StringTable::LookupKey(Isolate* isolate, HashTableKey* key) {
Handle<StringTable> table = isolate->factory()->string_table(); Handle<StringTable> table = isolate->factory()->string_table();
int entry = table->FindEntry(key); int entry = table->FindEntry(key);
...@@ -17390,7 +17379,7 @@ Handle<String> StringTable::LookupKey(Isolate* isolate, HashTableKey* key) { ...@@ -17390,7 +17379,7 @@ Handle<String> StringTable::LookupKey(Isolate* isolate, HashTableKey* key) {
namespace { namespace {
class StringTableNoAllocateKey : public HashTableKey { class StringTableNoAllocateKey : public StringTableKey {
public: public:
StringTableNoAllocateKey(String* string, uint32_t seed) StringTableNoAllocateKey(String* string, uint32_t seed)
: string_(string), length_(string->length()) { : string_(string), length_(string->length()) {
...@@ -17547,7 +17536,7 @@ Object* StringTable::LookupStringIfExists_NoAllocate(String* string) { ...@@ -17547,7 +17536,7 @@ Object* StringTable::LookupStringIfExists_NoAllocate(String* string) {
return Smi::FromInt(ResultSentinel::kNotFound); return Smi::FromInt(ResultSentinel::kNotFound);
} }
String* StringTable::LookupKeyIfExists(Isolate* isolate, HashTableKey* key) { String* StringTable::LookupKeyIfExists(Isolate* isolate, StringTableKey* key) {
Handle<StringTable> table = isolate->factory()->string_table(); Handle<StringTable> table = isolate->factory()->string_table();
int entry = table->FindEntry(isolate, key); int entry = table->FindEntry(isolate, key);
if (entry != kNotFound) return String::cast(table->KeyAt(entry)); if (entry != kNotFound) return String::cast(table->KeyAt(entry));
......
...@@ -15,11 +15,6 @@ namespace internal { ...@@ -15,11 +15,6 @@ namespace internal {
CAST_ACCESSOR(CompilationCacheTable) CAST_ACCESSOR(CompilationCacheTable)
Handle<Object> CompilationCacheShape::AsHandle(Isolate* isolate,
HashTableKey* key) {
return key->AsHandle(isolate);
}
uint32_t CompilationCacheShape::RegExpHash(String* string, Smi* flags) { uint32_t CompilationCacheShape::RegExpHash(String* string, Smi* flags) {
return string->Hash() + flags->value(); return string->Hash() + flags->value();
} }
......
...@@ -30,8 +30,6 @@ class CompilationCacheShape : public BaseShape<HashTableKey*> { ...@@ -30,8 +30,6 @@ class CompilationCacheShape : public BaseShape<HashTableKey*> {
static inline uint32_t HashForObject(Object* object); static inline uint32_t HashForObject(Object* object);
static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
static const int kPrefixSize = 0; static const int kPrefixSize = 0;
static const int kEntrySize = 3; static const int kEntrySize = 3;
}; };
......
...@@ -259,8 +259,6 @@ class HashTableKey { ...@@ -259,8 +259,6 @@ class HashTableKey {
virtual bool IsMatch(Object* other) = 0; virtual bool IsMatch(Object* other) = 0;
// Returns the hash value for this key. // Returns the hash value for this key.
virtual uint32_t Hash() = 0; virtual uint32_t Hash() = 0;
// Returns the key object for storing into the hash table.
MUST_USE_RESULT virtual Handle<Object> AsHandle(Isolate* isolate) = 0;
// Required. // Required.
virtual ~HashTableKey() {} virtual ~HashTableKey() {}
}; };
......
...@@ -192,7 +192,7 @@ Char FlatStringReader::Get(int index) { ...@@ -192,7 +192,7 @@ Char FlatStringReader::Get(int index) {
} }
template <typename Char> template <typename Char>
class SequentialStringKey : public HashTableKey { class SequentialStringKey : public StringTableKey {
public: public:
explicit SequentialStringKey(Vector<const Char> string, uint32_t seed) explicit SequentialStringKey(Vector<const Char> string, uint32_t seed)
: string_(string), hash_field_(0), seed_(seed) {} : string_(string), hash_field_(0), seed_(seed) {}
...@@ -223,7 +223,7 @@ class OneByteStringKey : public SequentialStringKey<uint8_t> { ...@@ -223,7 +223,7 @@ class OneByteStringKey : public SequentialStringKey<uint8_t> {
Handle<Object> AsHandle(Isolate* isolate) override; Handle<Object> AsHandle(Isolate* isolate) override;
}; };
class SeqOneByteSubStringKey : public HashTableKey { class SeqOneByteSubStringKey : public StringTableKey {
public: public:
SeqOneByteSubStringKey(Handle<SeqOneByteString> string, int from, int length) SeqOneByteSubStringKey(Handle<SeqOneByteString> string, int from, int length)
: string_(string), from_(from), length_(length) { : string_(string), from_(from), length_(length) {
...@@ -275,7 +275,7 @@ class TwoByteStringKey : public SequentialStringKey<uc16> { ...@@ -275,7 +275,7 @@ class TwoByteStringKey : public SequentialStringKey<uc16> {
}; };
// Utf8StringKey carries a vector of chars as key. // Utf8StringKey carries a vector of chars as key.
class Utf8StringKey : public HashTableKey { class Utf8StringKey : public StringTableKey {
public: public:
explicit Utf8StringKey(Vector<const char> string, uint32_t seed) explicit Utf8StringKey(Vector<const char> string, uint32_t seed)
: string_(string), hash_field_(0), seed_(seed) {} : string_(string), hash_field_(0), seed_(seed) {}
......
...@@ -13,17 +13,22 @@ ...@@ -13,17 +13,22 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class StringTableShape : public BaseShape<HashTableKey*> { class StringTableKey : public HashTableKey {
public: public:
static inline bool IsMatch(HashTableKey* key, Object* value) { virtual Handle<Object> AsHandle(Isolate* isolate) = 0;
};
class StringTableShape : public BaseShape<StringTableKey*> {
public:
static inline bool IsMatch(Key key, Object* value) {
return key->IsMatch(value); return key->IsMatch(value);
} }
static inline uint32_t Hash(HashTableKey* key) { return key->Hash(); } static inline uint32_t Hash(Key key) { return key->Hash(); }
static inline uint32_t HashForObject(Object* object); static inline uint32_t HashForObject(Object* object);
static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key); static inline Handle<Object> AsHandle(Isolate* isolate, Key key);
static const int kPrefixSize = 0; static const int kPrefixSize = 0;
static const int kEntrySize = 1; static const int kEntrySize = 1;
...@@ -41,8 +46,8 @@ class StringTable : public HashTable<StringTable, StringTableShape> { ...@@ -41,8 +46,8 @@ class StringTable : public HashTable<StringTable, StringTableShape> {
// added. The return value is the string found. // added. The return value is the string found.
V8_EXPORT_PRIVATE static Handle<String> LookupString(Isolate* isolate, V8_EXPORT_PRIVATE static Handle<String> LookupString(Isolate* isolate,
Handle<String> key); Handle<String> key);
static Handle<String> LookupKey(Isolate* isolate, HashTableKey* key); static Handle<String> LookupKey(Isolate* isolate, StringTableKey* key);
static String* LookupKeyIfExists(Isolate* isolate, HashTableKey* key); static String* LookupKeyIfExists(Isolate* isolate, StringTableKey* key);
// Tries to internalize given string and returns string handle on success // Tries to internalize given string and returns string handle on success
// or an empty handle otherwise. // or an empty handle otherwise.
......
...@@ -281,7 +281,7 @@ void Deserializer::PrintDisassembledCodeObjects() { ...@@ -281,7 +281,7 @@ void Deserializer::PrintDisassembledCodeObjects() {
} }
// Used to insert a deserialized internalized string into the string table. // Used to insert a deserialized internalized string into the string table.
class StringTableInsertionKey : public HashTableKey { class StringTableInsertionKey : public StringTableKey {
public: public:
explicit StringTableInsertionKey(String* string) explicit StringTableInsertionKey(String* string)
: string_(string), hash_(string->Hash()) { : string_(string), hash_(string->Hash()) {
......
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