Chromium Code Reviews| Index: src/objects.h |
| diff --git a/src/objects.h b/src/objects.h |
| index 4c0e6ed49ba1db6e08e1f38c5b57ce2f415085b4..2d31035df9e20d9d53d7e5f33ddfa1ae5a07737c 100644 |
| --- a/src/objects.h |
| +++ b/src/objects.h |
| @@ -1345,10 +1345,12 @@ class JSObject: public HeapObject { |
| }; |
| enum ElementsKind { |
| - // The only "fast" kind. |
| + // The "fast" kind for tagged values. Must be first to make it possible |
| + // to efficiently check maps if they have fast elements. |
| FAST_ELEMENTS, |
| - // All the kinds below are "slow". |
| + // The "slow" kind. |
| DICTIONARY_ELEMENTS, |
| + // The "fast" kind for external arrays |
| EXTERNAL_BYTE_ELEMENTS, |
| EXTERNAL_UNSIGNED_BYTE_ELEMENTS, |
| EXTERNAL_SHORT_ELEMENTS, |
| @@ -1357,9 +1359,18 @@ class JSObject: public HeapObject { |
| EXTERNAL_UNSIGNED_INT_ELEMENTS, |
| EXTERNAL_FLOAT_ELEMENTS, |
| EXTERNAL_DOUBLE_ELEMENTS, |
| - EXTERNAL_PIXEL_ELEMENTS |
| + EXTERNAL_PIXEL_ELEMENTS, |
| + |
| + // Derived constants from ElementsKind |
| + FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_BYTE_ELEMENTS, |
| + LAST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS, |
| + FIRST_ELEMENTS_KIND = FAST_ELEMENTS, |
| + LAST_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS |
| }; |
| + static const int kElementsKindCount = |
| + LAST_ELEMENTS_KIND - FIRST_ELEMENTS_KIND + 1; |
| + |
| // [properties]: Backing storage for properties. |
| // properties is a FixedArray in the fast case and a Dictionary in the |
| // slow case. |
| @@ -3745,31 +3756,27 @@ class Map: public HeapObject { |
| inline void set_is_extensible(bool value); |
| inline bool is_extensible(); |
| - // Tells whether the instance has fast elements. |
| - // Equivalent to instance->GetElementsKind() == FAST_ELEMENTS. |
| - inline void set_has_fast_elements(bool value) { |
| - if (value) { |
| - set_bit_field2(bit_field2() | (1 << kHasFastElements)); |
| - } else { |
| - set_bit_field2(bit_field2() & ~(1 << kHasFastElements)); |
| - } |
| + inline void set_elements_kind(JSObject::ElementsKind elements_kind) { |
| + ASSERT(elements_kind < JSObject::kElementsKindCount); |
| + ASSERT(JSObject::kElementsKindCount <= (1 << kElementsKindBitCount)); |
| + set_bit_field2((bit_field2() & ~kElementsKindMask) | |
| + (elements_kind << kElementsKindFirstBit)); |
|
Mads Ager (chromium)
2011/05/30 11:14:24
Rename kElementsKindFirstBit to kElementsKindShift
danno
2011/06/01 22:29:54
Done.
|
| + ASSERT(this->elements_kind() == elements_kind); |
| } |
| - inline bool has_fast_elements() { |
| - return ((1 << kHasFastElements) & bit_field2()) != 0; |
| + inline JSObject::ElementsKind elements_kind() { |
| + return static_cast<JSObject::ElementsKind>( |
| + (bit_field2() & kElementsKindMask) >> kElementsKindFirstBit); |
| } |
| - // Tells whether an instance has pixel array elements. |
| - inline void set_has_external_array_elements(bool value) { |
| - if (value) { |
| - set_bit_field2(bit_field2() | (1 << kHasExternalArrayElements)); |
| - } else { |
| - set_bit_field2(bit_field2() & ~(1 << kHasExternalArrayElements)); |
| - } |
| + inline bool has_fast_elements() { |
| + return elements_kind() == JSObject::FAST_ELEMENTS; |
| } |
| inline bool has_external_array_elements() { |
| - return ((1 << kHasExternalArrayElements) & bit_field2()) != 0; |
| + JSObject::ElementsKind kind(elements_kind()); |
| + return kind >= JSObject::FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND && |
| + kind <= JSObject::LAST_EXTERNAL_ARRAY_ELEMENTS_KIND; |
| } |
| // Tells whether the map is attached to SharedFunctionInfo |
| @@ -3990,13 +3997,23 @@ class Map: public HeapObject { |
| // Bit positions for bit field 2 |
| static const int kIsExtensible = 0; |
| static const int kFunctionWithPrototype = 1; |
| - static const int kHasFastElements = 2; |
| - static const int kStringWrapperSafeForDefaultValueOf = 3; |
| - static const int kAttachedToSharedFunctionInfo = 4; |
| - static const int kHasExternalArrayElements = 5; |
| + static const int kStringWrapperSafeForDefaultValueOf = 2; |
| + static const int kAttachedToSharedFunctionInfo = 3; |
| + // No bits can be used between kElementsKindFirstBit and kElementsKindLastBit |
|
Mads Ager (chromium)
2011/05/30 11:14:24
Since the elements kind is using the remaining bit
danno
2011/06/01 22:29:54
Done.
|
| + // for anything other than storing the ElementKind. |
| + static const int kElementsKindFirstBit = 4; |
| + static const int kElementsKindLastBit = 7; |
| + |
| + // Derived values from bit field 2 |
| + static const int kElementsKindBitCount = |
| + kElementsKindLastBit - kElementsKindFirstBit + 1; |
| + static const int kElementsKindMask = |
| + (-1 << kElementsKindFirstBit) & ((1 << (kElementsKindLastBit + 1)) - 1); |
| + static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( |
| + (JSObject::FAST_ELEMENTS + 1) << Map::kElementsKindFirstBit) - 1; |
| // Bit positions for bit field 3 |
| - static const int kIsShared = 1; |
| + static const int kIsShared = 0; |
| // Layout of the default cache. It holds alternating name and code objects. |
| static const int kCodeCacheEntrySize = 2; |