Chromium Code Reviews| Index: src/objects.cc |
| =================================================================== |
| --- src/objects.cc (revision 556) |
| +++ src/objects.cc (working copy) |
| @@ -5479,9 +5479,7 @@ |
| // This avoids allocation in HasProperty. |
| class NumberKey : public HashTableKey { |
| public: |
| - explicit NumberKey(uint32_t number) { |
| - number_ = number; |
| - } |
| + explicit NumberKey(uint32_t number) : number_(number) { } |
| private: |
| bool IsMatch(Object* number) { |
| @@ -5527,9 +5525,7 @@ |
| // StringKey simply carries a string object as key. |
| class StringKey : public HashTableKey { |
| public: |
| - explicit StringKey(String* string) { |
| - string_ = string; |
| - } |
| + explicit StringKey(String* string) : string_(string) { } |
| bool IsMatch(Object* string) { |
| return string_->Equals(String::cast(string)); |
| @@ -5845,9 +5841,7 @@ |
| // SymbolsKey used for HashTable where key is array of symbols. |
| class SymbolsKey : public HashTableKey { |
| public: |
| - explicit SymbolsKey(FixedArray* symbols) { |
| - symbols_ = symbols; |
| - } |
| + explicit SymbolsKey(FixedArray* symbols) : symbols_(symbols) { } |
| bool IsMatch(Object* symbols) { |
| FixedArray* o = FixedArray::cast(symbols); |
| @@ -5866,20 +5860,73 @@ |
| Object* GetObject() { return symbols_; } |
| static uint32_t SymbolsHash(Object* obj) { |
| - FixedArray* symbols_ = FixedArray::cast(obj); |
| - int len = symbols_->length(); |
| - uint32_t hash = 0; |
| + FixedArray* symbols = FixedArray::cast(obj); |
| + int len = symbols->length(); |
| + uint32_t hash = 0; |
| for (int i = 0; i < len; i++) { |
| - hash ^= String::cast(symbols_->get(i))->Hash(); |
| + hash ^= String::cast(symbols->get(i))->Hash(); |
| } |
| return hash; |
| } |
| bool IsStringKey() { return false; } |
| + private: |
| FixedArray* symbols_; |
| }; |
| + |
| +// MapNameKeys are used as keys in lookup caches. |
| +class MapNameKey : public HashTableKey { |
| + public: |
| + MapNameKey(Map* map, String* name) |
| + : map_(map), name_(name) { } |
| + |
| + virtual bool IsMatch(Object* other) { |
|
bak
2008/10/23 06:08:11
Why do you use the virtual keyword in this class?
|
| + if (!other->IsFixedArray()) return false; |
| + FixedArray* pair = FixedArray::cast(other); |
| + Map* map = Map::cast(pair->get(0)); |
| + if (map != map_) return false; |
| + String* name = String::cast(pair->get(1)); |
| + return name->Equals(name_); |
| + } |
| + |
| + typedef uint32_t (*HashFunction)(Object* obj); |
| + |
| + virtual HashFunction GetHashFunction() { return MapNameHash; } |
| + |
| + static uint32_t MapNameHashHelper(Map* map, String* name) { |
| + return reinterpret_cast<uint32_t>(map) ^ name->Hash(); |
| + } |
| + |
| + static uint32_t MapNameHash(Object* obj) { |
| + FixedArray* pair = FixedArray::cast(obj); |
| + Map* map = Map::cast(pair->get(0)); |
| + String* name = String::cast(pair->get(1)); |
| + return MapNameHashHelper(map, name); |
| + } |
| + |
| + virtual uint32_t Hash() { |
| + return MapNameHashHelper(map_, name_); |
| + } |
| + |
| + virtual Object* GetObject() { |
| + Object* obj = Heap::AllocateFixedArray(2); |
| + if (obj->IsFailure()) return obj; |
| + FixedArray* pair = FixedArray::cast(obj); |
| + pair->set(0, map_); |
| + pair->set(1, name_); |
| + return pair; |
| + } |
| + |
| + virtual bool IsStringKey() { return false; } |
| + |
| + private: |
| + Map* map_; |
| + String* name_; |
| +}; |
| + |
| + |
| Object* MapCache::Lookup(FixedArray* array) { |
| SymbolsKey key(array); |
| int entry = FindEntry(&key); |
| @@ -5905,6 +5952,34 @@ |
| } |
| +int LookupCache::Lookup(Map* map, String* name) { |
| + MapNameKey key(map, name); |
| + int entry = FindEntry(&key); |
| + if (entry != -1) { |
|
bak
2008/10/23 06:08:11
I find this easier to read.
if (entry == -1) retur
|
| + return Smi::cast(get(EntryToIndex(entry) + 1))->value(); |
| + } else { |
| + return -1; |
| + } |
| +} |
| + |
| + |
| +Object* LookupCache::Put(Map* map, String* name, int value) { |
| + MapNameKey key(map, name); |
| + Object* obj = EnsureCapacity(1, &key); |
| + if (obj->IsFailure()) return obj; |
| + Object* k = key.GetObject(); |
| + if (k->IsFailure()) return k; |
| + |
| + LookupCache* cache = reinterpret_cast<LookupCache*>(obj); |
| + int entry = cache->FindInsertionEntry(k, key.Hash()); |
| + int index = EntryToIndex(entry); |
| + cache->set(index, k); |
| + cache->set(index + 1, Smi::FromInt(value)); |
| + cache->ElementAdded(); |
| + return cache; |
| +} |
| + |
| + |
| Object* Dictionary::Allocate(int at_least_space_for) { |
| Object* obj = DictionaryBase::Allocate(at_least_space_for); |
| // Initialize the next enumeration index. |
| @@ -5915,6 +5990,7 @@ |
| return obj; |
| } |
| + |
| Object* Dictionary::GenerateNewEnumerationIndices() { |
| int length = NumberOfElements(); |