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

Unified Diff: sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart

Issue 177963002: Use List instead of Link in the type system. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 6 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: sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart b/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart
index dc2b8bb5adcff3fa0e33418006158f9586245fc2..b0032d579b3879b542ce8e532009654cd7313d1e 100644
--- a/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart
@@ -402,7 +402,7 @@ class RuntimeTypes {
String name = namer.uniqueNameForTypeConstantElement(type.element);
if (!type.element.isClass) return name;
InterfaceType interface = type;
- Link<DartType> variables = interface.element.typeVariables;
+ List<DartType> variables = interface.element.typeVariables;
// Type constants can currently only be raw types, so there is no point
// adding ground-term type parameters, as they would just be 'dynamic'.
// TODO(sra): Since the result string is used only in constructing constant
@@ -410,7 +410,7 @@ class RuntimeTypes {
// legal JavaScript identifer.
if (variables.isEmpty) return name;
String arguments =
- new List.filled(variables.slowLength(), 'dynamic').join(', ');
+ new List.filled(variables.length, 'dynamic').join(', ');
return '$name<$arguments>';
}
@@ -436,16 +436,17 @@ class RuntimeTypes {
// Run through both lists of type variables and check if the type variables
// are identical at each position. If they are not, we need to calculate a
// substitution function.
- Link<DartType> variables = cls.typeVariables;
- Link<DartType> arguments = type.typeArguments;
- while (!variables.isEmpty && !arguments.isEmpty) {
- if (variables.head.element != arguments.head.element) {
+ List<DartType> variables = cls.typeVariables;
+ List<DartType> arguments = type.typeArguments;
+ if (variables.length != arguments.length) {
+ return false;
+ }
+ for (int index = 0; index < variables.length; index++) {
+ if (variables[index].element != arguments[index].element) {
return false;
}
- variables = variables.tail;
- arguments = arguments.tail;
}
- return (variables.isEmpty == arguments.isEmpty);
+ return true;
}
/**
@@ -495,7 +496,7 @@ class RuntimeTypes {
// they are mixed into.
InterfaceType type = cls.thisType;
InterfaceType target = type.asInstanceOf(check);
- Link<DartType> typeVariables = cls.typeVariables;
+ List<DartType> typeVariables = cls.typeVariables;
if (typeVariables.isEmpty && !alwaysGenerateFunction) {
return new Substitution.list(target.typeArguments);
} else {
@@ -504,14 +505,13 @@ class RuntimeTypes {
}
jsAst.Expression getSubstitutionRepresentation(
- Link<DartType> types,
+ List<DartType> types,
OnVariableCallback onVariable) {
List<jsAst.ArrayElement> elements = <jsAst.ArrayElement>[];
int index = 0;
- for (; !types.isEmpty; types = types.tail, index++) {
- jsAst.Expression representation =
- getTypeRepresentation(types.head, onVariable);
- elements.add(new jsAst.ArrayElement(index, representation));
+ for (DartType type in types) {
+ jsAst.Expression representation = getTypeRepresentation(type, onVariable);
+ elements.add(new jsAst.ArrayElement(index++, representation));
}
return new jsAst.ArrayInitializer(index, elements);
}
@@ -528,9 +528,9 @@ class RuntimeTypes {
} else {
List<String> parameters = const <String>[];
if (contextClass != null) {
- parameters = contextClass.typeVariables.mapToList((type) {
+ parameters = contextClass.typeVariables.map((type) {
return type.toString();
- });
+ }).toList();
}
return js('function(#) { return # }', [parameters, encoding]);
}
@@ -571,10 +571,8 @@ class RuntimeTypes {
if (!type.returnType.isDynamic) return false;
if (!type.optionalParameterTypes.isEmpty) return false;
if (!type.namedParameterTypes.isEmpty) return false;
- for (Link<DartType> link = type.parameterTypes;
- !link.isEmpty;
- link = link.tail) {
- if (!link.head.isDynamic) return false;
+ for (DartType parameter in type.parameterTypes ) {
+ if (!parameter.isDynamic) return false;
}
return true;
}
@@ -589,10 +587,9 @@ class RuntimeTypes {
static int getTypeVariableIndex(TypeVariableElement variable) {
ClassElement classElement = variable.enclosingClass;
- Link<DartType> variables = classElement.typeVariables;
- for (int index = 0; !variables.isEmpty;
- index++, variables = variables.tail) {
- if (variables.head.element == variable) return index;
+ List<DartType> variables = classElement.typeVariables;
+ for (int index = 0; index < variables.length; index++) {
+ if (variables[index].element == variable) return index;
}
throw invariant(variable, false,
message: "Couldn't find type-variable index");
@@ -653,15 +650,15 @@ class TypeRepresentationGenerator extends DartTypeVisitor {
return type.treatAsRaw ? name : visitList(type.typeArguments, head: name);
}
- jsAst.Expression visitList(Link<DartType> types, {jsAst.Expression head}) {
+ jsAst.Expression visitList(List<DartType> types, {jsAst.Expression head}) {
int index = 0;
List<jsAst.ArrayElement> elements = <jsAst.ArrayElement>[];
if (head != null) {
elements.add(new jsAst.ArrayElement(0, head));
index++;
}
- for (Link<DartType> link = types; !link.isEmpty; link = link.tail) {
- elements.add(new jsAst.ArrayElement(index++, visit(link.head)));
+ for (DartType type in types) {
+ elements.add(new jsAst.ArrayElement(index++, visit(type)));
}
return new jsAst.ArrayInitializer(elements.length, elements);
}
@@ -690,14 +687,12 @@ class TypeRepresentationGenerator extends DartTypeVisitor {
}
if (!type.namedParameterTypes.isEmpty) {
List<jsAst.Property> namedArguments = <jsAst.Property>[];
- Link<String> names = type.namedParameters;
- Link<DartType> types = type.namedParameterTypes;
- while (!types.isEmpty) {
- assert(!names.isEmpty);
- jsAst.Expression name = js.string(names.head);
- namedArguments.add(new jsAst.Property(name, visit(types.head)));
- names = names.tail;
- types = types.tail;
+ List<String> names = type.namedParameters;
+ List<DartType> types = type.namedParameterTypes;
+ assert(types.length == names.length);
+ for (int index = 0; index < types.length; index++) {
+ jsAst.Expression name = js.string(names[index]);
+ namedArguments.add(new jsAst.Property(name, visit(types[index])));
}
addProperty(namer.functionTypeNamedParametersTag(),
new jsAst.ObjectInitializer(namedArguments));
@@ -761,9 +756,9 @@ class ArgumentCollector extends DartTypeVisitor {
/// Collect all types in the list as if they were arguments of an
/// InterfaceType.
- collectAll(Link<DartType> types) {
- for (Link<DartType> link = types; !link.isEmpty; link = link.tail) {
- link.head.accept(this, true);
+ collectAll(List<DartType> types) {
+ for (DartType type in types) {
+ type.accept(this, true);
}
}
@@ -842,12 +837,12 @@ class FunctionArgumentCollector extends DartTypeVisitor {
*/
class Substitution {
final bool isFunction;
- final Link<DartType> arguments;
- final Link<DartType> parameters;
+ final List<DartType> arguments;
+ final List<DartType> parameters;
Substitution.list(this.arguments)
: isFunction = false,
- parameters = const Link<DartType>();
+ parameters = const <DartType>[];
Substitution.function(this.arguments, this.parameters)
: isFunction = true;

Powered by Google App Engine
This is Rietveld 408576698