OLD | NEW |
---|---|
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 <iosfwd> | 8 #include <iosfwd> |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
(...skipping 2450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2461 // Gives access to raw memory which stores the array's data. | 2461 // Gives access to raw memory which stores the array's data. |
2462 inline Object** data_start(); | 2462 inline Object** data_start(); |
2463 | 2463 |
2464 inline void FillWithHoles(int from, int to); | 2464 inline void FillWithHoles(int from, int to); |
2465 | 2465 |
2466 // Shrink length and insert filler objects. | 2466 // Shrink length and insert filler objects. |
2467 void Shrink(int length); | 2467 void Shrink(int length); |
2468 | 2468 |
2469 enum KeyFilter { ALL_KEYS, NON_SYMBOL_KEYS }; | 2469 enum KeyFilter { ALL_KEYS, NON_SYMBOL_KEYS }; |
2470 | 2470 |
2471 // Add the elements of a JSArray to this FixedArray. | |
2472 MUST_USE_RESULT static MaybeHandle<FixedArray> AddKeysFromArrayLike( | |
2473 Handle<FixedArray> content, Handle<JSObject> array, | |
2474 KeyFilter filter = ALL_KEYS); | |
2475 | |
2476 // Computes the union of keys and return the result. | |
2477 // Used for implementing "for (n in object) { }" | |
2478 MUST_USE_RESULT static MaybeHandle<FixedArray> UnionOfKeys( | |
2479 Handle<FixedArray> first, | |
2480 Handle<FixedArray> second); | |
2481 | |
2482 // Copy a sub array from the receiver to dest. | 2471 // Copy a sub array from the receiver to dest. |
2483 void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); | 2472 void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); |
2484 | 2473 |
2485 // Garbage collection support. | 2474 // Garbage collection support. |
2486 static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } | 2475 static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } |
2487 | 2476 |
2488 // Code Generation support. | 2477 // Code Generation support. |
2489 static int OffsetOfElementAt(int index) { return SizeFor(index); } | 2478 static int OffsetOfElementAt(int index) { return SizeFor(index); } |
2490 | 2479 |
2491 // Garbage collection support. | 2480 // Garbage collection support. |
(...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3565 // Attempt to shrink hash table after removal of key. | 3554 // Attempt to shrink hash table after removal of key. |
3566 MUST_USE_RESULT static inline Handle<ObjectHashTable> Shrink( | 3555 MUST_USE_RESULT static inline Handle<ObjectHashTable> Shrink( |
3567 Handle<ObjectHashTable> table, | 3556 Handle<ObjectHashTable> table, |
3568 Handle<Object> key); | 3557 Handle<Object> key); |
3569 | 3558 |
3570 // Looks up the value associated with the given key. The hole value is | 3559 // Looks up the value associated with the given key. The hole value is |
3571 // returned in case the key is not present. | 3560 // returned in case the key is not present. |
3572 Object* Lookup(Handle<Object> key); | 3561 Object* Lookup(Handle<Object> key); |
3573 Object* Lookup(Handle<Object> key, int32_t hash); | 3562 Object* Lookup(Handle<Object> key, int32_t hash); |
3574 Object* Lookup(Isolate* isolate, Handle<Object> key, int32_t hash); | 3563 Object* Lookup(Isolate* isolate, Handle<Object> key, int32_t hash); |
3564 bool HasKey(Isolate* isolate, Handle<Object> key); | |
3575 | 3565 |
3576 // Adds (or overwrites) the value associated with the given key. | 3566 // Adds (or overwrites) the value associated with the given key. |
3577 static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table, | 3567 static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table, |
3578 Handle<Object> key, | 3568 Handle<Object> key, |
3579 Handle<Object> value); | 3569 Handle<Object> value); |
3580 static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table, | 3570 static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table, |
3581 Handle<Object> key, Handle<Object> value, | 3571 Handle<Object> key, Handle<Object> value, |
3582 int32_t hash); | 3572 int32_t hash); |
3573 static Handle<ObjectHashTable> Put(Isolate* isolate, | |
3574 Handle<ObjectHashTable> table, | |
3575 Handle<Object> key, Handle<Object> value); | |
3576 static Handle<ObjectHashTable> Put(Isolate* isolate, | |
3577 Handle<ObjectHashTable> table, | |
3578 Handle<Object> key, Handle<Object> value, | |
3579 int32_t hash); | |
3583 | 3580 |
3584 // Returns an ObjectHashTable (possibly |table|) where |key| has been removed. | 3581 // Returns an ObjectHashTable (possibly |table|) where |key| has been removed. |
3585 static Handle<ObjectHashTable> Remove(Handle<ObjectHashTable> table, | 3582 static Handle<ObjectHashTable> Remove(Handle<ObjectHashTable> table, |
3586 Handle<Object> key, | 3583 Handle<Object> key, |
3587 bool* was_present); | 3584 bool* was_present); |
3588 static Handle<ObjectHashTable> Remove(Handle<ObjectHashTable> table, | 3585 static Handle<ObjectHashTable> Remove(Handle<ObjectHashTable> table, |
3589 Handle<Object> key, bool* was_present, | 3586 Handle<Object> key, bool* was_present, |
3590 int32_t hash); | 3587 int32_t hash); |
3591 | 3588 |
3592 protected: | 3589 protected: |
(...skipping 6870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10463 static inline int set(int value, int bit_position, bool v) { | 10460 static inline int set(int value, int bit_position, bool v) { |
10464 if (v) { | 10461 if (v) { |
10465 value |= (1 << bit_position); | 10462 value |= (1 << bit_position); |
10466 } else { | 10463 } else { |
10467 value &= ~(1 << bit_position); | 10464 value &= ~(1 << bit_position); |
10468 } | 10465 } |
10469 return value; | 10466 return value; |
10470 } | 10467 } |
10471 }; | 10468 }; |
10472 | 10469 |
10470 | |
10471 class KeyAccumulator final BASE_EMBEDDED { | |
Camillo Bruni
2015/09/14 07:45:40
I wasn't really sure where to put the class declar
| |
10472 public: | |
10473 explicit KeyAccumulator(Isolate* isolate) | |
10474 : isolate_(isolate), keys_(), set_(), length_(0) {} | |
Igor Sheludko
2015/09/17 09:55:11
keys_() and set_() are not really necessary here.
| |
10475 | |
10476 void AddKeys(Handle<FixedArray> array, FixedArray::KeyFilter filter); | |
10477 void AddKeys(Handle<JSObject> array, FixedArray::KeyFilter filter); | |
10478 Handle<FixedArray> GetKeys(); | |
10479 int GetLength(); | |
10480 bool HasKey(Handle<Object> key, int limit); | |
10481 void AddKey(Handle<Object> key); | |
10482 void PrepareForComparisons(int count); | |
10483 | |
10484 private: | |
10485 void EnsureCapacity(int capacity); | |
10486 void Grow(); | |
10487 | |
10488 Isolate* isolate_; | |
10489 Handle<FixedArray> keys_; | |
10490 Handle<ObjectHashTable> set_; | |
10491 int length_; | |
10492 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); | |
10493 }; | |
10473 } } // namespace v8::internal | 10494 } } // namespace v8::internal |
10474 | 10495 |
10475 #endif // V8_OBJECTS_H_ | 10496 #endif // V8_OBJECTS_H_ |
OLD | NEW |