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

Unified Diff: pkg/kernel/lib/transformations/closure/converter.dart

Issue 2743363007: Don't create a closure class if it already exists (Closed)
Patch Set: Created 3 years, 9 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/transformations/closure/converter.dart
diff --git a/pkg/kernel/lib/transformations/closure/converter.dart b/pkg/kernel/lib/transformations/closure/converter.dart
index 325d9e54abdc5fb050024fc2b00409feaa271f8d..9ebd806e1dd6344c1593c272fb21142a0446fb86 100644
--- a/pkg/kernel/lib/transformations/closure/converter.dart
+++ b/pkg/kernel/lib/transformations/closure/converter.dart
@@ -671,12 +671,26 @@ class ClosureConverter extends Transformer {
fields = <Field>[self];
receiver = new PropertyGet(new ThisExpression(), self.name, self);
}
- Class closureClass = createClosureClass(procedure.function,
- fields: fields, substitution: substitution);
- closureClass.addMember(new Procedure(new Name("call"), ProcedureKind.Method,
- forwardFunction(procedure, receiver, substitution),
- fileUri: currentFileUri));
- newLibraryMembers.add(closureClass);
+
+ // Find the closure class for the function. If there isn't one, create it.
+ String closureClassName = createNameForClosureClass(procedure.function);
+ Class closureClass = null;
+ for (TreeNode node in newLibraryMembers) {
+ if (node is Class && (node as Class).name == closureClassName) {
+ closureClass = node as Class;
+ }
+ }
+ if (closureClass == null) {
+ closureClass = createClosureClass(procedure.function,
+ fields: fields, substitution: substitution);
+ closureClass.addMember(new Procedure(
+ new Name("call"),
+ ProcedureKind.Method,
+ forwardFunction(procedure, receiver, substitution),
+ fileUri: currentFileUri));
+ newLibraryMembers.add(closureClass);
+ }
+
Arguments constructorArguments = procedure.isInstanceMember
? new Arguments(<Expression>[new ThisExpression()])
: new Arguments.empty();
@@ -747,13 +761,17 @@ class ClosureConverter extends Transformer {
return substitution;
}
+ String createNameForClosureClass(FunctionNode function) {
+ return 'Closure#${localNames[function]}';
+ }
+
Class createClosureClass(FunctionNode function,
{List<Field> fields, Map<TypeParameter, DartType> substitution}) {
List<TypeParameter> typeParameters = new List<TypeParameter>.from(
substitution.values
.map((DartType t) => (t as TypeParameterType).parameter));
Class closureClass = new Class(
- name: 'Closure#${localNames[function]}',
+ name: createNameForClosureClass(function),
supertype: new Supertype(coreTypes.objectClass, const <DartType>[]),
typeParameters: typeParameters,
implementedTypes: <Supertype>[
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698