Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: runtime/vm/type_table.h

Issue 1965493004: Canonicalize generic types in an isolate specific hash table (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address-merge-conflicts Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/service.cc ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/type_table.h
diff --git a/runtime/vm/type_table.h b/runtime/vm/type_table.h
new file mode 100644
index 0000000000000000000000000000000000000000..c33a124a63cb596d7b400d21a2e3fb2385d5d23a
--- /dev/null
+++ b/runtime/vm/type_table.h
@@ -0,0 +1,112 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#ifndef VM_TYPE_TABLE_H_
+#define VM_TYPE_TABLE_H_
+
+#include "platform/assert.h"
+#include "vm/hash_table.h"
+#include "vm/object.h"
+
+namespace dart {
+
+class CanonicalTypeKey {
+ public:
+ explicit CanonicalTypeKey(const Type& key) : key_(key) {
+ }
+ bool Matches(const Type& arg) const {
+ return key_.Equals(arg);
+ }
+ uword Hash() const {
+ return key_.Hash();
+ }
+ const Type& key_;
+
+ private:
+ DISALLOW_ALLOCATION();
+};
+
+
+// Traits for looking up Canonical Type based on it's hash.
+class CanonicalTypeTraits {
+ public:
+ static const char* Name() { return "CanonicalTypeTraits"; }
+ static bool ReportStats() { return false; }
+
+ // Called when growing the table.
+ static bool IsMatch(const Object& a, const Object& b) {
+ ASSERT(a.IsType() && b.IsType());
+ const Type& arg1 = Type::Cast(a);
+ const Type& arg2 = Type::Cast(b);
+ return arg1.Equals(arg2) && (arg1.Hash() == arg2.Hash());
+ }
+ static bool IsMatch(const CanonicalTypeKey& a, const Object& b) {
+ ASSERT(b.IsType());
+ return a.Matches(Type::Cast(b));
+ }
+ static uword Hash(const Object& key) {
+ ASSERT(key.IsType());
+ return Type::Cast(key).Hash();
+ }
+ static uword Hash(const CanonicalTypeKey& key) {
+ return key.Hash();
+ }
+ static RawObject* NewKey(const CanonicalTypeKey& obj) {
+ return obj.key_.raw();
+ }
+};
+typedef UnorderedHashSet <CanonicalTypeTraits> CanonicalTypeSet;
+
+
+class CanonicalTypeArgumentsKey {
+ public:
+ explicit CanonicalTypeArgumentsKey(const TypeArguments& key) : key_(key) {
+ }
+ bool Matches(const TypeArguments& arg) const {
+ return key_.Equals(arg) && (key_.Hash() == arg.Hash());
+ }
+ uword Hash() const {
+ return key_.Hash();
+ }
+ const TypeArguments& key_;
+
+ private:
+ DISALLOW_ALLOCATION();
+};
+
+
+// Traits for looking up Canonical TypeArguments based on its hash.
+class CanonicalTypeArgumentsTraits {
+ public:
+ static const char* Name() { return "CanonicalTypeArgumentsTraits"; }
+ static bool ReportStats() { return false; }
+
+ // Called when growing the table.
+ static bool IsMatch(const Object& a, const Object& b) {
+ ASSERT(a.IsTypeArguments() && b.IsTypeArguments());
+ const TypeArguments& arg1 = TypeArguments::Cast(a);
+ const TypeArguments& arg2 = TypeArguments::Cast(b);
+ return arg1.Equals(arg2) && (arg1.Hash() == arg2.Hash());
+ }
+ static bool IsMatch(const CanonicalTypeArgumentsKey& a, const Object& b) {
+ ASSERT(b.IsTypeArguments());
+ return a.Matches(TypeArguments::Cast(b));
+ }
+ static uword Hash(const Object& key) {
+ ASSERT(key.IsTypeArguments());
+ return TypeArguments::Cast(key).Hash();
+ }
+ static uword Hash(const CanonicalTypeArgumentsKey& key) {
+ return key.Hash();
+ }
+ static RawObject* NewKey(const CanonicalTypeArgumentsKey& obj) {
+ return obj.key_.raw();
+ }
+};
+typedef UnorderedHashSet<CanonicalTypeArgumentsTraits>
+ CanonicalTypeArgumentsSet;
+
+} // namespace dart
+
+#endif // VM_TYPE_TABLE_H_
« no previous file with comments | « runtime/vm/service.cc ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698