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

Unified Diff: runtime/vm/object.h

Issue 1309613002: Avoid numerous type allocations by caching the canonical type of a class, which (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address comments Created 5 years, 4 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
Index: runtime/vm/object.h
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index bdfab97cd5745c957ab6ab8ed107a36b363f1301..0a2e742c93f857a4afb6d11121d001b2ad6f6210 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -1034,12 +1034,16 @@ class Class : public Object {
return OFFSET_OF(RawClass, type_arguments_field_offset_in_words_);
}
- RawType* CanonicalType() const {
- if ((NumTypeArguments() == 0) && !IsSignatureClass()) {
- return reinterpret_cast<RawType*>(raw_ptr()->canonical_types_);
- }
- return reinterpret_cast<RawType*>(Object::null());
- }
+ // Returns the cached canonical type of this class, i.e. the canonical type
+ // whose type class is this class and whose type arguments are the
+ // uninstantiated type parameters declared by this class if it is generic,
+ // e.g. Map<K, V>.
+ // Returns Type::null() if the canonical type is not cached yet.
+ RawType* CanonicalType() const;
+
+ // Caches the canonical type of this class.
+ void SetCanonicalType(const Type& type) const;
+
static intptr_t canonical_types_offset() {
return OFFSET_OF(RawClass, canonical_types_);
}
@@ -1193,7 +1197,6 @@ class Class : public Object {
void InsertCanonicalConstant(intptr_t index, const Instance& constant) const;
- intptr_t NumCanonicalTypes() const;
intptr_t FindCanonicalTypeIndex(const Type& needle) const;
RawType* CanonicalTypeFromIndex(intptr_t idx) const;
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/object.cc » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698