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

Side by Side Diff: src/objects.cc

Issue 373323002: Avoid unnecessary hashing in OrderedHashTable (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/allocation-site-scopes.h" 8 #include "src/allocation-site-scopes.h"
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/arguments.h" 10 #include "src/arguments.h"
(...skipping 16122 matching lines...) Expand 10 before | Expand all | Expand 10 after
16133 16133
16134 new_table->SetNumberOfElements(nof); 16134 new_table->SetNumberOfElements(nof);
16135 table->SetNextTable(*new_table); 16135 table->SetNextTable(*new_table);
16136 16136
16137 return new_table; 16137 return new_table;
16138 } 16138 }
16139 16139
16140 16140
16141 template<class Derived, class Iterator, int entrysize> 16141 template<class Derived, class Iterator, int entrysize>
16142 int OrderedHashTable<Derived, Iterator, entrysize>::FindEntry( 16142 int OrderedHashTable<Derived, Iterator, entrysize>::FindEntry(
16143 Handle<Object> key) { 16143 Handle<Object> key, int hash) {
16144 ASSERT(!IsObsolete()); 16144 ASSERT(!IsObsolete());
16145 16145
16146 DisallowHeapAllocation no_gc; 16146 DisallowHeapAllocation no_gc;
16147 ASSERT(!key->IsTheHole()); 16147 ASSERT(!key->IsTheHole());
16148 Object* hash = key->GetHash(); 16148 for (int entry = HashToEntry(hash);
16149 if (hash->IsUndefined()) return kNotFound;
16150 for (int entry = HashToEntry(Smi::cast(hash)->value());
16151 entry != kNotFound; 16149 entry != kNotFound;
16152 entry = ChainAt(entry)) { 16150 entry = ChainAt(entry)) {
16153 Object* candidate = KeyAt(entry); 16151 Object* candidate = KeyAt(entry);
16154 if (candidate->SameValueZero(*key)) 16152 if (candidate->SameValueZero(*key))
16155 return entry; 16153 return entry;
16156 } 16154 }
16157 return kNotFound; 16155 return kNotFound;
16158 } 16156 }
16159 16157
16160 16158
16161 template<class Derived, class Iterator, int entrysize> 16159 template<class Derived, class Iterator, int entrysize>
16160 int OrderedHashTable<Derived, Iterator, entrysize>::FindEntry(
16161 Handle<Object> key) {
16162 DisallowHeapAllocation no_gc;
16163 Object* hash = key->GetHash();
16164 if (!hash->IsSmi()) return kNotFound;
16165 return FindEntry(key, Smi::cast(hash)->value());
16166 }
16167
16168
16169 template<class Derived, class Iterator, int entrysize>
16162 int OrderedHashTable<Derived, Iterator, entrysize>::AddEntry(int hash) { 16170 int OrderedHashTable<Derived, Iterator, entrysize>::AddEntry(int hash) {
16163 ASSERT(!IsObsolete()); 16171 ASSERT(!IsObsolete());
16164 16172
16165 int entry = UsedCapacity(); 16173 int entry = UsedCapacity();
16166 int bucket = HashToBucket(hash); 16174 int bucket = HashToBucket(hash);
16167 int index = EntryToIndex(entry); 16175 int index = EntryToIndex(entry);
16168 Object* chain_entry = get(kHashTableStartIndex + bucket); 16176 Object* chain_entry = get(kHashTableStartIndex + bucket);
16169 set(kHashTableStartIndex + bucket, Smi::FromInt(entry)); 16177 set(kHashTableStartIndex + bucket, Smi::FromInt(entry));
16170 set(index + kChainOffset, chain_entry); 16178 set(index + kChainOffset, chain_entry);
16171 SetNumberOfElements(NumberOfElements() + 1); 16179 SetNumberOfElements(NumberOfElements() + 1);
(...skipping 29 matching lines...) Expand all
16201 template Handle<OrderedHashSet> 16209 template Handle<OrderedHashSet>
16202 OrderedHashTable<OrderedHashSet, JSSetIterator, 1>::Clear( 16210 OrderedHashTable<OrderedHashSet, JSSetIterator, 1>::Clear(
16203 Handle<OrderedHashSet> table); 16211 Handle<OrderedHashSet> table);
16204 16212
16205 template Handle<OrderedHashSet> 16213 template Handle<OrderedHashSet>
16206 OrderedHashTable<OrderedHashSet, JSSetIterator, 1>::Remove( 16214 OrderedHashTable<OrderedHashSet, JSSetIterator, 1>::Remove(
16207 Handle<OrderedHashSet> table, Handle<Object> key, bool* was_present); 16215 Handle<OrderedHashSet> table, Handle<Object> key, bool* was_present);
16208 16216
16209 template int 16217 template int
16210 OrderedHashTable<OrderedHashSet, JSSetIterator, 1>::FindEntry( 16218 OrderedHashTable<OrderedHashSet, JSSetIterator, 1>::FindEntry(
16219 Handle<Object> key, int hash);
16220 template int
16221 OrderedHashTable<OrderedHashSet, JSSetIterator, 1>::FindEntry(
16211 Handle<Object> key); 16222 Handle<Object> key);
16212 16223
16213 template int 16224 template int
16214 OrderedHashTable<OrderedHashSet, JSSetIterator, 1>::AddEntry(int hash); 16225 OrderedHashTable<OrderedHashSet, JSSetIterator, 1>::AddEntry(int hash);
16215 16226
16216 template void 16227 template void
16217 OrderedHashTable<OrderedHashSet, JSSetIterator, 1>::RemoveEntry(int entry); 16228 OrderedHashTable<OrderedHashSet, JSSetIterator, 1>::RemoveEntry(int entry);
16218 16229
16219 16230
16220 template Handle<OrderedHashMap> 16231 template Handle<OrderedHashMap>
(...skipping 11 matching lines...) Expand all
16232 template Handle<OrderedHashMap> 16243 template Handle<OrderedHashMap>
16233 OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::Clear( 16244 OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::Clear(
16234 Handle<OrderedHashMap> table); 16245 Handle<OrderedHashMap> table);
16235 16246
16236 template Handle<OrderedHashMap> 16247 template Handle<OrderedHashMap>
16237 OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::Remove( 16248 OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::Remove(
16238 Handle<OrderedHashMap> table, Handle<Object> key, bool* was_present); 16249 Handle<OrderedHashMap> table, Handle<Object> key, bool* was_present);
16239 16250
16240 template int 16251 template int
16241 OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::FindEntry( 16252 OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::FindEntry(
16253 Handle<Object> key, int hash);
16254 template int
16255 OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::FindEntry(
16242 Handle<Object> key); 16256 Handle<Object> key);
16243 16257
16244 template int 16258 template int
16245 OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::AddEntry(int hash); 16259 OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::AddEntry(int hash);
16246 16260
16247 template void 16261 template void
16248 OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::RemoveEntry(int entry); 16262 OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::RemoveEntry(int entry);
16249 16263
16250 16264
16251 bool OrderedHashSet::Contains(Handle<Object> key) { 16265 bool OrderedHashSet::Contains(Handle<Object> key) {
16252 return FindEntry(key) != kNotFound; 16266 return FindEntry(key) != kNotFound;
16253 } 16267 }
16254 16268
16255 16269
16256 Handle<OrderedHashSet> OrderedHashSet::Add(Handle<OrderedHashSet> table, 16270 Handle<OrderedHashSet> OrderedHashSet::Add(Handle<OrderedHashSet> table,
16257 Handle<Object> key) { 16271 Handle<Object> key) {
16258 if (table->FindEntry(key) != kNotFound) return table; 16272 int hash = GetOrCreateHash(table->GetIsolate(), key)->value();
16273 if (table->FindEntry(key, hash) != kNotFound) return table;
16259 16274
16260 table = EnsureGrowable(table); 16275 table = EnsureGrowable(table);
16261 16276
16262 Handle<Smi> hash = GetOrCreateHash(table->GetIsolate(), key); 16277 int index = table->AddEntry(hash);
16263 int index = table->AddEntry(hash->value());
16264 table->set(index, *key); 16278 table->set(index, *key);
16265 return table; 16279 return table;
16266 } 16280 }
16267 16281
16268 16282
16269 Object* OrderedHashMap::Lookup(Handle<Object> key) { 16283 Object* OrderedHashMap::Lookup(Handle<Object> key) {
16270 DisallowHeapAllocation no_gc; 16284 DisallowHeapAllocation no_gc;
16271 int entry = FindEntry(key); 16285 int entry = FindEntry(key);
16272 if (entry == kNotFound) return GetHeap()->the_hole_value(); 16286 if (entry == kNotFound) return GetHeap()->the_hole_value();
16273 return ValueAt(entry); 16287 return ValueAt(entry);
16274 } 16288 }
16275 16289
16276 16290
16277 Handle<OrderedHashMap> OrderedHashMap::Put(Handle<OrderedHashMap> table, 16291 Handle<OrderedHashMap> OrderedHashMap::Put(Handle<OrderedHashMap> table,
16278 Handle<Object> key, 16292 Handle<Object> key,
16279 Handle<Object> value) { 16293 Handle<Object> value) {
16280 ASSERT(!key->IsTheHole()); 16294 ASSERT(!key->IsTheHole());
16281 16295
16282 int entry = table->FindEntry(key); 16296 int hash = GetOrCreateHash(table->GetIsolate(), key)->value();
16297 int entry = table->FindEntry(key, hash);
16283 16298
16284 if (entry != kNotFound) { 16299 if (entry != kNotFound) {
16285 table->set(table->EntryToIndex(entry) + kValueOffset, *value); 16300 table->set(table->EntryToIndex(entry) + kValueOffset, *value);
16286 return table; 16301 return table;
16287 } 16302 }
16288 16303
16289 table = EnsureGrowable(table); 16304 table = EnsureGrowable(table);
16290 16305
16291 Handle<Smi> hash = GetOrCreateHash(table->GetIsolate(), key); 16306 int index = table->AddEntry(hash);
16292 int index = table->AddEntry(hash->value());
16293 table->set(index, *key); 16307 table->set(index, *key);
16294 table->set(index + kValueOffset, *value); 16308 table->set(index + kValueOffset, *value);
16295 return table; 16309 return table;
16296 } 16310 }
16297 16311
16298 16312
16299 template<class Derived, class TableType> 16313 template<class Derived, class TableType>
16300 void OrderedHashTableIterator<Derived, TableType>::Transition() { 16314 void OrderedHashTableIterator<Derived, TableType>::Transition() {
16301 DisallowHeapAllocation no_allocation; 16315 DisallowHeapAllocation no_allocation;
16302 TableType* table = TableType::cast(this->table()); 16316 TableType* table = TableType::cast(this->table());
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
16986 #define ERROR_MESSAGES_TEXTS(C, T) T, 17000 #define ERROR_MESSAGES_TEXTS(C, T) T,
16987 static const char* error_messages_[] = { 17001 static const char* error_messages_[] = {
16988 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 17002 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16989 }; 17003 };
16990 #undef ERROR_MESSAGES_TEXTS 17004 #undef ERROR_MESSAGES_TEXTS
16991 return error_messages_[reason]; 17005 return error_messages_[reason];
16992 } 17006 }
16993 17007
16994 17008
16995 } } // namespace v8::internal 17009 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698