Index: runtime/vm/object.h |
diff --git a/runtime/vm/object.h b/runtime/vm/object.h |
index a2f8d2143204ac0b8207e82621fffedec0c3fcd6..f6caa4eea982138bf4df1e7be32fd62892086804 100644 |
--- a/runtime/vm/object.h |
+++ b/runtime/vm/object.h |
@@ -1717,8 +1717,8 @@ class TypeArguments : public Object { |
static intptr_t InstanceSize(intptr_t len) { |
// Ensure that the types() is not adding to the object size, which includes |
- // 2 fields: instantiations_ and length_. |
- ASSERT(sizeof(RawTypeArguments) == (sizeof(RawObject) + (2 * kWordSize))); |
+ // 3 fields: instantiations_, length_ and hash_. |
+ ASSERT(sizeof(RawTypeArguments) == (sizeof(RawObject) + (3 * kWordSize))); |
ASSERT(0 <= len && len <= kMaxElements); |
return RoundedAllocationSize( |
sizeof(RawTypeArguments) + (len * kBytesPerElement)); |
@@ -1729,6 +1729,9 @@ class TypeArguments : public Object { |
static RawTypeArguments* New(intptr_t len, Heap::Space space = Heap::kOld); |
private: |
+ intptr_t ComputeHash() const; |
+ void SetHash(intptr_t value) const; |
+ |
// Check if the subvector of length 'len' starting at 'from_index' of this |
// type argument vector consists solely of DynamicType. |
// If raw_instantiated is true, consider each type parameter to be first |
@@ -5685,6 +5688,9 @@ class Type : public AbstractType { |
Heap::Space space = Heap::kOld); |
private: |
+ intptr_t ComputeHash() const; |
+ void SetHash(intptr_t value) const; |
+ |
void set_token_pos(TokenPosition token_pos) const; |
void set_type_state(int8_t state) const; |
@@ -5836,6 +5842,9 @@ class TypeParameter : public AbstractType { |
TokenPosition token_pos); |
private: |
+ intptr_t ComputeHash() const; |
+ void SetHash(intptr_t value) const; |
+ |
void set_parameterized_class(const Class& value) const; |
void set_name(const String& value) const; |
void set_token_pos(TokenPosition token_pos) const; |
@@ -5921,6 +5930,9 @@ class BoundedType : public AbstractType { |
const TypeParameter& type_parameter); |
private: |
+ intptr_t ComputeHash() const; |
+ void SetHash(intptr_t value) const; |
+ |
void set_type(const AbstractType& value) const; |
void set_bound(const AbstractType& value) const; |
void set_type_parameter(const TypeParameter& value) const; |
@@ -8528,6 +8540,72 @@ RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
return array.At((index * kEntryLength) + kTargetFunctionIndex); |
} |
+ |
+inline intptr_t Type::Hash() const { |
+ intptr_t result = Smi::Value(raw_ptr()->hash_); |
+ if (result != 0) { |
regis
2016/05/10 18:14:26
What if the hash is 0?
siva
2016/05/13 23:16:13
I have fixed this similar to the StringHasher to r
|
+ return result; |
+ } |
+ return ComputeHash(); |
+} |
+ |
+ |
+inline void Type::SetHash(intptr_t value) const { |
+ // This is only safe because we create a new Smi, which does not cause |
+ // heap allocation. |
+ StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
+} |
+ |
+ |
+inline intptr_t TypeParameter::Hash() const { |
+ ASSERT(IsFinalized()); |
+ intptr_t result = Smi::Value(raw_ptr()->hash_); |
+ if (result != 0) { |
+ return result; |
+ } |
+ return ComputeHash(); |
+} |
+ |
+ |
+inline void TypeParameter::SetHash(intptr_t value) const { |
+ // This is only safe because we create a new Smi, which does not cause |
+ // heap allocation. |
+ StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
regis
2016/05/10 18:14:26
What if the value does not fit in a Smi?
siva
2016/05/13 23:16:13
I have fixed this similar to the StringHasher by h
|
+} |
+ |
+ |
+inline intptr_t BoundedType::Hash() const { |
+ intptr_t result = Smi::Value(raw_ptr()->hash_); |
+ if (result != 0) { |
+ return result; |
+ } |
+ return ComputeHash(); |
+} |
+ |
+ |
+inline void BoundedType::SetHash(intptr_t value) const { |
+ // This is only safe because we create a new Smi, which does not cause |
+ // heap allocation. |
+ StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
+} |
+ |
+ |
+inline intptr_t TypeArguments::Hash() const { |
+ if (IsNull()) return 0; |
+ intptr_t result = Smi::Value(raw_ptr()->hash_); |
+ if (result != 0) { |
+ return result; |
+ } |
+ return ComputeHash(); |
+} |
+ |
+ |
+inline void TypeArguments::SetHash(intptr_t value) const { |
+ // This is only safe because we create a new Smi, which does not cause |
+ // heap allocation. |
+ StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
+} |
+ |
} // namespace dart |
#endif // VM_OBJECT_H_ |