Chromium Code Reviews| Index: src/objects.cc |
| diff --git a/src/objects.cc b/src/objects.cc |
| index 65fa9eedc17dd731c2013347e58cc9e9acd6755f..0feab8a60472246c073d460d78cc9aacc83e8426 100644 |
| --- a/src/objects.cc |
| +++ b/src/objects.cc |
| @@ -5551,6 +5551,46 @@ class StringKey : public HashTableKey { |
| String* string_; |
| }; |
| +// RegExpKey carries a regexp object as key. |
|
Kasper Lund
2008/10/24 06:42:50
Is this really so? It seems to hold a string and s
|
| +class RegExpKey : public HashTableKey { |
| + public: |
| + RegExpKey(String* string, int flags) |
| + : string_(string), |
| + flags_(Smi::FromInt(flags)) { } |
| + |
| + bool IsMatch(Object* obj) { |
| + FixedArray* val = FixedArray::cast(obj); |
| + return string_->Equals(String::cast(val->get(JSRegExp::kSourceIndex))) |
| + && (flags_ == val->get(JSRegExp::kFlagsIndex)); |
| + } |
| + |
| + uint32_t Hash() { return RegExpHash(string_, flags_); } |
| + |
| + HashFunction GetHashFunction() { return RegExpObjHash; } |
| + |
| + Object* GetObject() { |
| + // Plain hash maps, which is where regexp keys are used, don't |
| + // use this function. |
| + UNREACHABLE(); |
| + return NULL; |
| + } |
| + |
| + static uint32_t RegExpObjHash(Object* obj) { |
|
Kasper Lund
2008/10/24 06:42:50
I don't like the Obj abbreviation here. RegExpObje
|
| + FixedArray* val = FixedArray::cast(obj); |
| + return RegExpHash(String::cast(val->get(JSRegExp::kSourceIndex)), |
| + Smi::cast(val->get(JSRegExp::kFlagsIndex))); |
| + } |
| + |
| + static uint32_t RegExpHash(String* string, Smi* flags) { |
| + return string->Hash() + flags->value(); |
| + } |
| + |
| + bool IsStringKey() { return false; } |
| + |
| + String* string_; |
| + Smi* flags_; |
| +}; |
| + |
| // Utf8SymbolKey carries a vector of chars as key. |
| class Utf8SymbolKey : public HashTableKey { |
| public: |
| @@ -5825,6 +5865,14 @@ Object* CompilationCacheTable::Lookup(String* src) { |
| } |
| +Object* CompilationCacheTable::LookupRegExp(String* source, int flags) { |
| + RegExpKey key(source, flags); |
| + int entry = FindEntry(&key); |
| + if (entry == -1) return Heap::undefined_value(); |
| + return get(EntryToIndex(entry) + 1); |
| +} |
| + |
| + |
| Object* CompilationCacheTable::Put(String* src, Object* value) { |
| StringKey key(src); |
| Object* obj = EnsureCapacity(1, &key); |
| @@ -5840,6 +5888,23 @@ Object* CompilationCacheTable::Put(String* src, Object* value) { |
| } |
| +Object* CompilationCacheTable::PutRegExp(String* src, |
| + int flags, |
| + FixedArray* value) { |
| + RegExpKey key(src, flags); |
| + Object* obj = EnsureCapacity(1, &key); |
| + if (obj->IsFailure()) return obj; |
| + |
| + CompilationCacheTable* cache = |
| + reinterpret_cast<CompilationCacheTable*>(obj); |
| + int entry = cache->FindInsertionEntry(value, key.Hash()); |
| + cache->set(EntryToIndex(entry), value); |
| + cache->set(EntryToIndex(entry) + 1, value); |
| + cache->ElementAdded(); |
| + return cache; |
| +} |
| + |
| + |
| // SymbolsKey used for HashTable where key is array of symbols. |
| class SymbolsKey : public HashTableKey { |
| public: |