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

Unified Diff: pkg/compiler/lib/src/js_backend/namer.dart

Issue 1215223002: dart2js: Reuse names for constructor bodes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Comments Created 5 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
« no previous file with comments | « pkg/compiler/lib/src/js_backend/minify_namer.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_backend/namer.dart
diff --git a/pkg/compiler/lib/src/js_backend/namer.dart b/pkg/compiler/lib/src/js_backend/namer.dart
index 1dac9f9a201d67e57c54ecbaebf3e1bfe13c31de..17e9d5fac1de32c7d6692d44fea4e590af12ed85 100644
--- a/pkg/compiler/lib/src/js_backend/namer.dart
+++ b/pkg/compiler/lib/src/js_backend/namer.dart
@@ -585,11 +585,16 @@ class Namer {
return '$name\$${suffix.join(r'$')}';
}
+ /// Name for a constructor body.
+ jsAst.Name constructorBodyName(FunctionElement ctor) {
+ return _disambiguateInternalMember(ctor,
+ () => _proposeNameForConstructorBody(ctor));
+ }
+
/// Annotated name for [method] encoding arity and named parameters.
jsAst.Name instanceMethodName(FunctionElement method) {
if (method.isGenerativeConstructorBody) {
- return _disambiguateInternalMember(method,
- () => _proposeNameForConstructorBody(method));
+ return constructorBodyName(method);
}
return invocationName(new Selector.fromElement(method));
}
@@ -917,6 +922,30 @@ class Namer {
return newName;
}
+ /// Returns the disambiguated name for the instance member identified by
+ /// [key].
+ ///
+ /// When a name for an element is requested by key, it may not be requested
+ /// by element at the same time, as two different names would be returned.
+ ///
+ /// If key has not yet been registered, [proposeName] is used to generate
+ /// a name proposal for the given key.
+ ///
+ /// [key] must not clash with valid instance names. This is typically
+ /// achieved by using at least one character in [key] that is not valid in
+ /// identifiers, for example the @ symbol.
+ jsAst.Name _disambiguateMemberByKey(String key, String proposeName()) {
+ jsAst.Name newName = userInstanceMembers[key];
+ if (newName == null) {
+ String name = proposeName();
+ newName = getFreshName(name,
+ usedInstanceNames, suggestedInstanceNames,
+ sanitizeForAnnotations: true);
+ userInstanceMembers[key] = newName;
+ }
+ return newName;
+ }
+
/// Forces the public instance member with [originalName] to have the given
/// [disambiguatedName].
///
« no previous file with comments | « pkg/compiler/lib/src/js_backend/minify_namer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698