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

Side by Side Diff: src/objects.h

Issue 329253004: Optimize Map/Set.prototype.forEach (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Update count to fix merge issue Created 6 years, 6 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #ifndef V8_OBJECTS_H_ 5 #ifndef V8_OBJECTS_H_
6 #define V8_OBJECTS_H_ 6 #define V8_OBJECTS_H_
7 7
8 #include "src/allocation.h" 8 #include "src/allocation.h"
9 #include "src/assert-scope.h" 9 #include "src/assert-scope.h"
10 #include "src/builtins.h" 10 #include "src/builtins.h"
(...skipping 4472 matching lines...) Expand 10 before | Expand all | Expand 10 after
4483 ASSERT(obj->IsOrderedHashTable()); 4483 ASSERT(obj->IsOrderedHashTable());
4484 return reinterpret_cast<OrderedHashMap*>(obj); 4484 return reinterpret_cast<OrderedHashMap*>(obj);
4485 } 4485 }
4486 4486
4487 Object* Lookup(Handle<Object> key); 4487 Object* Lookup(Handle<Object> key);
4488 static Handle<OrderedHashMap> Put( 4488 static Handle<OrderedHashMap> Put(
4489 Handle<OrderedHashMap> table, 4489 Handle<OrderedHashMap> table,
4490 Handle<Object> key, 4490 Handle<Object> key,
4491 Handle<Object> value); 4491 Handle<Object> value);
4492 4492
4493 private:
4494 Object* ValueAt(int entry) { 4493 Object* ValueAt(int entry) {
4495 return get(EntryToIndex(entry) + kValueOffset); 4494 return get(EntryToIndex(entry) + kValueOffset);
4496 } 4495 }
4497 4496
4497 private:
4498 static const int kValueOffset = 1; 4498 static const int kValueOffset = 1;
4499 }; 4499 };
4500 4500
4501 4501
4502 template <int entrysize> 4502 template <int entrysize>
4503 class WeakHashTableShape : public BaseShape<Handle<Object> > { 4503 class WeakHashTableShape : public BaseShape<Handle<Object> > {
4504 public: 4504 public:
4505 static inline bool IsMatch(Handle<Object> key, Object* other); 4505 static inline bool IsMatch(Handle<Object> key, Object* other);
4506 static inline uint32_t Hash(Handle<Object> key); 4506 static inline uint32_t Hash(Handle<Object> key);
4507 static inline uint32_t HashForObject(Handle<Object> key, Object* object); 4507 static inline uint32_t HashForObject(Handle<Object> key, Object* object);
(...skipping 5664 matching lines...) Expand 10 before | Expand all | Expand 10 after
10172 kKindKeys = 1, 10172 kKindKeys = 1,
10173 kKindValues = 2, 10173 kKindValues = 2,
10174 kKindEntries = 3 10174 kKindEntries = 3
10175 }; 10175 };
10176 10176
10177 // Returns an iterator result object: {value: any, done: boolean} and moves 10177 // Returns an iterator result object: {value: any, done: boolean} and moves
10178 // the index to the next valid entry. Closes the iterator if moving past the 10178 // the index to the next valid entry. Closes the iterator if moving past the
10179 // end. 10179 // end.
10180 static Handle<JSObject> Next(Handle<Derived> iterator); 10180 static Handle<JSObject> Next(Handle<Derived> iterator);
10181 10181
10182 // Whether the iterator has more elements. This needs to be called before
10183 // calling |CurrentKey| and/or |CurrentValue|.
10184 bool HasMore();
10185
10186 // Move the index forward one.
10187 void MoveNext() {
10188 set_index(Smi::FromInt(Smi::cast(index())->value() + 1));
10189 }
10190
10191 // Returns the current key of the iterator. This should only be called when
10192 // |HasMore| returns true.
10193 inline Object* CurrentKey();
10194
10182 private: 10195 private:
10183 // Transitions the iterator to the non obsolote backing store. This is a NOP 10196 // Transitions the iterator to the non obsolete backing store. This is a NOP
10184 // if the [table] is not obsolete. 10197 // if the [table] is not obsolete.
10185 void Transition(); 10198 void Transition();
10186 10199
10187 DISALLOW_IMPLICIT_CONSTRUCTORS(OrderedHashTableIterator); 10200 DISALLOW_IMPLICIT_CONSTRUCTORS(OrderedHashTableIterator);
10188 }; 10201 };
10189 10202
10190 10203
10191 class JSSetIterator: public OrderedHashTableIterator<JSSetIterator, 10204 class JSSetIterator: public OrderedHashTableIterator<JSSetIterator,
10192 OrderedHashSet> { 10205 OrderedHashSet> {
10193 public: 10206 public:
10194 // Dispatched behavior. 10207 // Dispatched behavior.
10195 DECLARE_PRINTER(JSSetIterator) 10208 DECLARE_PRINTER(JSSetIterator)
10196 DECLARE_VERIFIER(JSSetIterator) 10209 DECLARE_VERIFIER(JSSetIterator)
10197 10210
10198 // Casting. 10211 // Casting.
10199 static inline JSSetIterator* cast(Object* obj); 10212 static inline JSSetIterator* cast(Object* obj);
10200 10213
10201 static Handle<Object> ValueForKind( 10214 // Returns the iterator result value at the current |index| taking the |kind|
10202 Handle<JSSetIterator> iterator, 10215 // into account. This should only be called when |HasMore| returns true.
10203 int entry_index); 10216 static Handle<Object> CurrentIteratorResultValue(
10217 Handle<JSSetIterator> iterator);
10204 10218
10205 private: 10219 private:
10206 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSetIterator); 10220 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSetIterator);
10207 }; 10221 };
10208 10222
10209 10223
10210 class JSMapIterator: public OrderedHashTableIterator<JSMapIterator, 10224 class JSMapIterator: public OrderedHashTableIterator<JSMapIterator,
10211 OrderedHashMap> { 10225 OrderedHashMap> {
10212 public: 10226 public:
10213 // Dispatched behavior. 10227 // Dispatched behavior.
10214 DECLARE_PRINTER(JSMapIterator) 10228 DECLARE_PRINTER(JSMapIterator)
10215 DECLARE_VERIFIER(JSMapIterator) 10229 DECLARE_VERIFIER(JSMapIterator)
10216 10230
10217 // Casting. 10231 // Casting.
10218 static inline JSMapIterator* cast(Object* obj); 10232 static inline JSMapIterator* cast(Object* obj);
10219 10233
10220 static Handle<Object> ValueForKind( 10234 // Returns the iterator result value at the current |index| taking the |kind|
10221 Handle<JSMapIterator> iterator, 10235 // into account. This should only be called when |HasMore| returns true.
10222 int entry_index); 10236 static Handle<Object> CurrentIteratorResultValue(
10237 Handle<JSMapIterator> iterator);
10238
10239 // Returns the current value of the iterator. This should only be called when
10240 // |HasMore| returns true.
10241 inline Object* CurrentValue();
10223 10242
10224 private: 10243 private:
10225 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMapIterator); 10244 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMapIterator);
10226 }; 10245 };
10227 10246
10228 10247
10229 // Base class for both JSWeakMap and JSWeakSet 10248 // Base class for both JSWeakMap and JSWeakSet
10230 class JSWeakCollection: public JSObject { 10249 class JSWeakCollection: public JSObject {
10231 public: 10250 public:
10232 // [table]: the backing hash table mapping keys to values. 10251 // [table]: the backing hash table mapping keys to values.
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after
11249 } else { 11268 } else {
11250 value &= ~(1 << bit_position); 11269 value &= ~(1 << bit_position);
11251 } 11270 }
11252 return value; 11271 return value;
11253 } 11272 }
11254 }; 11273 };
11255 11274
11256 } } // namespace v8::internal 11275 } } // namespace v8::internal
11257 11276
11258 #endif // V8_OBJECTS_H_ 11277 #endif // V8_OBJECTS_H_
OLDNEW
« src/collection.js ('K') | « src/collection.js ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698