| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 3018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3029 MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor( | 3029 MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor( |
| 3030 JSObject* obj, | 3030 JSObject* obj, |
| 3031 int unused_property_fields); | 3031 int unused_property_fields); |
| 3032 | 3032 |
| 3033 // Find entry for key, otherwise return kNotFound. Optimized version of | 3033 // Find entry for key, otherwise return kNotFound. Optimized version of |
| 3034 // HashTable::FindEntry. | 3034 // HashTable::FindEntry. |
| 3035 int FindEntry(String* key); | 3035 int FindEntry(String* key); |
| 3036 }; | 3036 }; |
| 3037 | 3037 |
| 3038 | 3038 |
| 3039 enum NumberDictionaryKind { |
| 3040 kNotSeeded = 0, |
| 3041 kSeeded |
| 3042 }; |
| 3043 |
| 3044 |
| 3045 template <NumberDictionaryKind kind> |
| 3039 class NumberDictionaryShape : public BaseShape<uint32_t> { | 3046 class NumberDictionaryShape : public BaseShape<uint32_t> { |
| 3040 public: | 3047 public: |
| 3041 static const bool UsesSeed = true; | 3048 static const bool UsesSeed = kind; |
| 3042 | 3049 |
| 3043 static inline bool IsMatch(uint32_t key, Object* other); | 3050 static inline bool IsMatch(uint32_t key, Object* other); |
| 3044 static inline uint32_t Hash(uint32_t key); | 3051 static inline uint32_t Hash(uint32_t key); |
| 3045 static inline uint32_t SeededHash(uint32_t key, uint32_t seed); | 3052 static inline uint32_t SeededHash(uint32_t key, uint32_t seed); |
| 3046 static inline uint32_t HashForObject(uint32_t key, Object* object); | 3053 static inline uint32_t HashForObject(uint32_t key, Object* object); |
| 3047 static inline uint32_t SeededHashForObject(uint32_t key, | 3054 static inline uint32_t SeededHashForObject(uint32_t key, |
| 3048 uint32_t seed, | 3055 uint32_t seed, |
| 3049 Object* object); | 3056 Object* object); |
| 3050 MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key); | 3057 MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key); |
| 3051 static const int kPrefixSize = 2; | 3058 static const int kPrefixSize = 2; |
| 3052 static const int kEntrySize = 3; | 3059 static const int kEntrySize = 3; |
| 3053 static const bool kIsEnumerable = false; | 3060 static const bool kIsEnumerable = false; |
| 3054 }; | 3061 }; |
| 3055 | 3062 |
| 3056 | 3063 |
| 3057 class NumberDictionary: public Dictionary<NumberDictionaryShape, uint32_t> { | 3064 class NumberDictionaryBase { |
| 3058 public: | 3065 public: |
| 3059 static NumberDictionary* cast(Object* obj) { | |
| 3060 ASSERT(obj->IsDictionary()); | |
| 3061 return reinterpret_cast<NumberDictionary*>(obj); | |
| 3062 } | |
| 3063 | |
| 3064 // Type specific at put (default NONE attributes is used when adding). | 3066 // Type specific at put (default NONE attributes is used when adding). |
| 3065 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); | 3067 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
| 3066 MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, | 3068 MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, |
| 3067 Object* value, | 3069 Object* value, |
| 3068 PropertyDetails details); | 3070 PropertyDetails details); |
| 3069 | 3071 |
| 3070 // Set an existing entry or add a new one if needed. | |
| 3071 // Return the updated dictionary. | |
| 3072 MUST_USE_RESULT static Handle<NumberDictionary> Set( | |
| 3073 Handle<NumberDictionary> dictionary, | |
| 3074 uint32_t index, | |
| 3075 Handle<Object> value, | |
| 3076 PropertyDetails details); | |
| 3077 | 3072 |
| 3078 MUST_USE_RESULT MaybeObject* Set(uint32_t key, | 3073 MUST_USE_RESULT MaybeObject* Set(uint32_t key, |
| 3079 Object* value, | 3074 Object* value, |
| 3080 PropertyDetails details); | 3075 PropertyDetails details); |
| 3081 | 3076 |
| 3082 void UpdateMaxNumberKey(uint32_t key); | 3077 void UpdateMaxNumberKey(uint32_t key); |
| 3083 | 3078 |
| 3084 // If slow elements are required we will never go back to fast-case | 3079 // If slow elements are required we will never go back to fast-case |
| 3085 // for the elements kept in this dictionary. We require slow | 3080 // for the elements kept in this dictionary. We require slow |
| 3086 // elements if an element has been added at an index larger than | 3081 // elements if an element has been added at an index larger than |
| 3087 // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called | 3082 // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called |
| 3088 // when defining a getter or setter with a number key. | 3083 // when defining a getter or setter with a number key. |
| 3089 inline bool requires_slow_elements(); | 3084 inline bool requires_slow_elements(); |
| 3090 inline void set_requires_slow_elements(); | 3085 inline void set_requires_slow_elements(); |
| 3091 | 3086 |
| 3092 // Get the value of the max number key that has been added to this | 3087 // Get the value of the max number key that has been added to this |
| 3093 // dictionary. max_number_key can only be called if | 3088 // dictionary. max_number_key can only be called if |
| 3094 // requires_slow_elements returns false. | 3089 // requires_slow_elements returns false. |
| 3095 inline uint32_t max_number_key(); | 3090 inline uint32_t max_number_key(); |
| 3096 | 3091 |
| 3092 protected: |
| 3097 // Bit masks. | 3093 // Bit masks. |
| 3098 static const int kRequiresSlowElementsMask = 1; | 3094 static const int kRequiresSlowElementsMask = 1; |
| 3099 static const int kRequiresSlowElementsTagSize = 1; | 3095 static const int kRequiresSlowElementsTagSize = 1; |
| 3100 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; | 3096 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
| 3097 |
| 3098 private: |
| 3099 // Internal function for easier conversion |
| 3100 inline NumberDictionary* as_dict() { |
| 3101 return reinterpret_cast<NumberDictionary*>(this); |
| 3102 } |
| 3101 }; | 3103 }; |
| 3102 | 3104 |
| 3103 | 3105 |
| 3106 class NumberDictionary : |
| 3107 public Dictionary<NumberDictionaryShape<kSeeded>, uint32_t>, |
| 3108 public NumberDictionaryBase { |
| 3109 public: |
| 3110 static NumberDictionary* cast(Object* obj) { |
| 3111 ASSERT(obj->IsDictionary()); |
| 3112 return reinterpret_cast<NumberDictionary*>(obj); |
| 3113 } |
| 3114 |
| 3115 MUST_USE_RESULT MaybeObject* Set(uint32_t key, |
| 3116 Object* value, |
| 3117 PropertyDetails details) { |
| 3118 return NumberDictionaryBase::Set(key, value, details); |
| 3119 } |
| 3120 |
| 3121 // Set an existing entry or add a new one if needed. |
| 3122 // Return the updated dictionary. |
| 3123 MUST_USE_RESULT static Handle<NumberDictionary> Set( |
| 3124 Handle<NumberDictionary> dictionary, |
| 3125 uint32_t index, |
| 3126 Handle<Object> value, |
| 3127 PropertyDetails details); |
| 3128 |
| 3129 friend class NumberDictionaryBase; |
| 3130 }; |
| 3131 |
| 3132 |
| 3133 class NotSeededNumberDictionary : |
| 3134 public Dictionary<NumberDictionaryShape<kNotSeeded>, uint32_t>, |
| 3135 public NumberDictionaryBase { |
| 3136 public: |
| 3137 static NotSeededNumberDictionary* cast(Object* obj) { |
| 3138 ASSERT(obj->IsDictionary()); |
| 3139 return reinterpret_cast<NotSeededNumberDictionary*>(obj); |
| 3140 } |
| 3141 |
| 3142 MUST_USE_RESULT MaybeObject* Set(uint32_t key, |
| 3143 Object* value, |
| 3144 PropertyDetails details) { |
| 3145 return NumberDictionaryBase::Set(key, value, details); |
| 3146 } |
| 3147 |
| 3148 // Set an existing entry or add a new one if needed. |
| 3149 // Return the updated dictionary. |
| 3150 MUST_USE_RESULT static Handle<NotSeededNumberDictionary> Set( |
| 3151 Handle<NotSeededNumberDictionary> dictionary, |
| 3152 uint32_t index, |
| 3153 Handle<Object> value, |
| 3154 PropertyDetails details); |
| 3155 }; |
| 3156 |
| 3157 |
| 3104 template <int entrysize> | 3158 template <int entrysize> |
| 3105 class ObjectHashTableShape : public BaseShape<Object*> { | 3159 class ObjectHashTableShape : public BaseShape<Object*> { |
| 3106 public: | 3160 public: |
| 3107 static inline bool IsMatch(Object* key, Object* other); | 3161 static inline bool IsMatch(Object* key, Object* other); |
| 3108 static inline uint32_t Hash(Object* key); | 3162 static inline uint32_t Hash(Object* key); |
| 3109 static inline uint32_t HashForObject(Object* key, Object* object); | 3163 static inline uint32_t HashForObject(Object* key, Object* object); |
| 3110 MUST_USE_RESULT static inline MaybeObject* AsObject(Object* key); | 3164 MUST_USE_RESULT static inline MaybeObject* AsObject(Object* key); |
| 3111 static const int kPrefixSize = 0; | 3165 static const int kPrefixSize = 0; |
| 3112 static const int kEntrySize = entrysize; | 3166 static const int kEntrySize = entrysize; |
| 3113 }; | 3167 }; |
| (...skipping 5040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8154 } else { | 8208 } else { |
| 8155 value &= ~(1 << bit_position); | 8209 value &= ~(1 << bit_position); |
| 8156 } | 8210 } |
| 8157 return value; | 8211 return value; |
| 8158 } | 8212 } |
| 8159 }; | 8213 }; |
| 8160 | 8214 |
| 8161 } } // namespace v8::internal | 8215 } } // namespace v8::internal |
| 8162 | 8216 |
| 8163 #endif // V8_OBJECTS_H_ | 8217 #endif // V8_OBJECTS_H_ |
| OLD | NEW |