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

Unified Diff: runtime/vm/object.cc

Issue 14106013: Further improve type optimization reusing the type argument vector of the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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/object.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 22154)
+++ runtime/vm/object.cc (working copy)
@@ -2619,6 +2619,14 @@
}
+bool AbstractTypeArguments::CanShareInstantiatorTypeArguments(
+ const Class& instantiator_class) const {
+ // AbstractTypeArguments is an abstract class.
+ UNREACHABLE();
+ return false;
+}
+
+
bool AbstractTypeArguments::IsBounded() const {
// AbstractTypeArguments is an abstract class.
UNREACHABLE();
@@ -2848,7 +2856,7 @@
bool TypeArguments::IsUninstantiatedIdentity() const {
ASSERT(!IsInstantiated());
AbstractType& type = AbstractType::Handle();
- intptr_t num_types = Length();
+ const intptr_t num_types = Length();
for (intptr_t i = 0; i < num_types; i++) {
type = TypeAt(i);
if (!type.IsTypeParameter()) {
@@ -2870,9 +2878,65 @@
}
}
return true;
+ // Note that it is not necessary to verify at runtime that the instantiator
+ // type vector is long enough, since this uninstantiated vector contains as
+ // many different type parameters as it is long.
}
+bool TypeArguments::CanShareInstantiatorTypeArguments(
+ const Class& instantiator_class) const {
+ ASSERT(!IsInstantiated());
+ const intptr_t num_instantiator_type_args =
+ instantiator_class.NumTypeArguments();
+ const intptr_t num_instantiator_type_params =
+ instantiator_class.NumTypeParameters();
+ const intptr_t num_super_instantiator_type_args =
+ num_instantiator_type_args - num_instantiator_type_params;
+ const intptr_t num_type_args = Length();
+ // As a first requirement in order to share the instantiator type argument
+ // vector, this type argument vector must refer to the type parameters of the
+ // instantiator class in declaration order. It does not need to contain all
+ // type parameters.
+ if (num_type_args < num_super_instantiator_type_args) {
+ return false;
+ }
+ AbstractType& type_arg = AbstractType::Handle();
+ for (intptr_t i = num_super_instantiator_type_args; i < num_type_args; i++) {
+ type_arg = TypeAt(i);
+ if (!type_arg.IsTypeParameter()) {
+ return false;
+ }
+ const TypeParameter& type_param = TypeParameter::Cast(type_arg);
+ ASSERT(type_param.IsFinalized());
+ if ((type_param.index() != i)) {
+ return false;
+ }
+ }
+ // As a second requirement, the type arguments corresponding to the super type
+ // must be identical.
+ if (num_super_instantiator_type_args == 0) {
+ return true;
+ }
+ AbstractType& super_type = AbstractType::Handle(
+ instantiator_class.super_type());
+ const AbstractTypeArguments& super_type_args = AbstractTypeArguments::Handle(
+ super_type.arguments());
+ if (super_type_args.IsNull()) {
+ return false;
+ }
+ AbstractType& super_type_arg = AbstractType::Handle();
+ for (intptr_t i = 0; i < num_super_instantiator_type_args; i++) {
+ type_arg = TypeAt(i);
+ super_type_arg = super_type_args.TypeAt(i);
+ if (!type_arg.Equals(super_type_arg)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+
bool TypeArguments::IsBounded() const {
AbstractType& type = AbstractType::Handle();
intptr_t num_types = Length();
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698