| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef RUNTIME_VM_TYPE_TABLE_H_ | 5 #ifndef RUNTIME_VM_TYPE_TABLE_H_ |
| 6 #define RUNTIME_VM_TYPE_TABLE_H_ | 6 #define RUNTIME_VM_TYPE_TABLE_H_ |
| 7 | 7 |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/hash_table.h" | 9 #include "vm/hash_table.h" |
| 10 #include "vm/object.h" | 10 #include "vm/object.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 class CanonicalTypeKey { | 14 class CanonicalTypeKey { |
| 15 public: | 15 public: |
| 16 explicit CanonicalTypeKey(const Type& key) : key_(key) {} | 16 explicit CanonicalTypeKey(const Type& key) : key_(key) {} |
| 17 bool Matches(const Type& arg) const { return key_.Equals(arg); } | 17 bool Matches(const Type& arg) const { return key_.Equals(arg); } |
| 18 uword Hash() const { return key_.Hash(); } | 18 uword Hash() const { return key_.Hash(); } |
| 19 const Type& key_; | 19 const Type& key_; |
| 20 | 20 |
| 21 private: | 21 private: |
| 22 DISALLOW_ALLOCATION(); | 22 DISALLOW_ALLOCATION(); |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 | |
| 26 // Traits for looking up Canonical Type based on it's hash. | 25 // Traits for looking up Canonical Type based on it's hash. |
| 27 class CanonicalTypeTraits { | 26 class CanonicalTypeTraits { |
| 28 public: | 27 public: |
| 29 static const char* Name() { return "CanonicalTypeTraits"; } | 28 static const char* Name() { return "CanonicalTypeTraits"; } |
| 30 static bool ReportStats() { return false; } | 29 static bool ReportStats() { return false; } |
| 31 | 30 |
| 32 // Called when growing the table. | 31 // Called when growing the table. |
| 33 static bool IsMatch(const Object& a, const Object& b) { | 32 static bool IsMatch(const Object& a, const Object& b) { |
| 34 ASSERT(a.IsType() && b.IsType()); | 33 ASSERT(a.IsType() && b.IsType()); |
| 35 const Type& arg1 = Type::Cast(a); | 34 const Type& arg1 = Type::Cast(a); |
| 36 const Type& arg2 = Type::Cast(b); | 35 const Type& arg2 = Type::Cast(b); |
| 37 return arg1.Equals(arg2) && (arg1.Hash() == arg2.Hash()); | 36 return arg1.Equals(arg2) && (arg1.Hash() == arg2.Hash()); |
| 38 } | 37 } |
| 39 static bool IsMatch(const CanonicalTypeKey& a, const Object& b) { | 38 static bool IsMatch(const CanonicalTypeKey& a, const Object& b) { |
| 40 ASSERT(b.IsType()); | 39 ASSERT(b.IsType()); |
| 41 return a.Matches(Type::Cast(b)); | 40 return a.Matches(Type::Cast(b)); |
| 42 } | 41 } |
| 43 static uword Hash(const Object& key) { | 42 static uword Hash(const Object& key) { |
| 44 ASSERT(key.IsType()); | 43 ASSERT(key.IsType()); |
| 45 return Type::Cast(key).Hash(); | 44 return Type::Cast(key).Hash(); |
| 46 } | 45 } |
| 47 static uword Hash(const CanonicalTypeKey& key) { return key.Hash(); } | 46 static uword Hash(const CanonicalTypeKey& key) { return key.Hash(); } |
| 48 static RawObject* NewKey(const CanonicalTypeKey& obj) { | 47 static RawObject* NewKey(const CanonicalTypeKey& obj) { |
| 49 return obj.key_.raw(); | 48 return obj.key_.raw(); |
| 50 } | 49 } |
| 51 }; | 50 }; |
| 52 typedef UnorderedHashSet<CanonicalTypeTraits> CanonicalTypeSet; | 51 typedef UnorderedHashSet<CanonicalTypeTraits> CanonicalTypeSet; |
| 53 | 52 |
| 54 | |
| 55 class CanonicalTypeArgumentsKey { | 53 class CanonicalTypeArgumentsKey { |
| 56 public: | 54 public: |
| 57 explicit CanonicalTypeArgumentsKey(const TypeArguments& key) : key_(key) {} | 55 explicit CanonicalTypeArgumentsKey(const TypeArguments& key) : key_(key) {} |
| 58 bool Matches(const TypeArguments& arg) const { | 56 bool Matches(const TypeArguments& arg) const { |
| 59 return key_.Equals(arg) && (key_.Hash() == arg.Hash()); | 57 return key_.Equals(arg) && (key_.Hash() == arg.Hash()); |
| 60 } | 58 } |
| 61 uword Hash() const { return key_.Hash(); } | 59 uword Hash() const { return key_.Hash(); } |
| 62 const TypeArguments& key_; | 60 const TypeArguments& key_; |
| 63 | 61 |
| 64 private: | 62 private: |
| 65 DISALLOW_ALLOCATION(); | 63 DISALLOW_ALLOCATION(); |
| 66 }; | 64 }; |
| 67 | 65 |
| 68 | |
| 69 // Traits for looking up Canonical TypeArguments based on its hash. | 66 // Traits for looking up Canonical TypeArguments based on its hash. |
| 70 class CanonicalTypeArgumentsTraits { | 67 class CanonicalTypeArgumentsTraits { |
| 71 public: | 68 public: |
| 72 static const char* Name() { return "CanonicalTypeArgumentsTraits"; } | 69 static const char* Name() { return "CanonicalTypeArgumentsTraits"; } |
| 73 static bool ReportStats() { return false; } | 70 static bool ReportStats() { return false; } |
| 74 | 71 |
| 75 // Called when growing the table. | 72 // Called when growing the table. |
| 76 static bool IsMatch(const Object& a, const Object& b) { | 73 static bool IsMatch(const Object& a, const Object& b) { |
| 77 ASSERT(a.IsTypeArguments() && b.IsTypeArguments()); | 74 ASSERT(a.IsTypeArguments() && b.IsTypeArguments()); |
| 78 const TypeArguments& arg1 = TypeArguments::Cast(a); | 75 const TypeArguments& arg1 = TypeArguments::Cast(a); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 91 static RawObject* NewKey(const CanonicalTypeArgumentsKey& obj) { | 88 static RawObject* NewKey(const CanonicalTypeArgumentsKey& obj) { |
| 92 return obj.key_.raw(); | 89 return obj.key_.raw(); |
| 93 } | 90 } |
| 94 }; | 91 }; |
| 95 typedef UnorderedHashSet<CanonicalTypeArgumentsTraits> | 92 typedef UnorderedHashSet<CanonicalTypeArgumentsTraits> |
| 96 CanonicalTypeArgumentsSet; | 93 CanonicalTypeArgumentsSet; |
| 97 | 94 |
| 98 } // namespace dart | 95 } // namespace dart |
| 99 | 96 |
| 100 #endif // RUNTIME_VM_TYPE_TABLE_H_ | 97 #endif // RUNTIME_VM_TYPE_TABLE_H_ |
| OLD | NEW |