Skip to content

Commit 6d33d03

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
Cache prototype references while installing aliases
A.Foo.prototype.method1Alias = A.Foo.prototype.method1 A.Foo.prototype.method2Alias = A.Foo.prototype.method2 ... --> (function aliases() { var _ = A.Foo.prototype _.method1Alias = _.method1 _.method2Alias = _.method2 ... })() Change-Id: Ia0c2844b0a3bba6eefe7cff63085a9e307cfb2ae Reviewed-on: https://dart-review.googlesource.com/c/86320 Reviewed-by: Sigmund Cherem <[email protected]> Commit-Queue: Stephen Adams <[email protected]>
1 parent 1b3e2cc commit 6d33d03

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,19 +1260,24 @@ class FragmentEmitter {
12601260
for (Library library in fragment.libraries) {
12611261
for (Class cls in library.classes) {
12621262
if (cls.isSoftDeferred != softDeferred) continue;
1263+
bool firstAlias = true;
12631264
for (InstanceMethod method in cls.methods) {
12641265
if (method.aliasName != null) {
1265-
assignments.add(js.js.statement('#.prototype.# = #.prototype.#', [
1266-
classReference(cls),
1267-
js.quoteName(method.aliasName),
1268-
classReference(cls),
1269-
js.quoteName(method.name)
1270-
]));
1266+
if (firstAlias) {
1267+
firstAlias = false;
1268+
assignments.add(js.js.statement(
1269+
assignments.isEmpty
1270+
? 'var _ = #.prototype;'
1271+
: '_ = #.prototype',
1272+
classReference(cls)));
1273+
}
1274+
assignments.add(js.js.statement('_.# = _.#',
1275+
[js.quoteName(method.aliasName), js.quoteName(method.name)]));
12711276
}
12721277
}
12731278
}
12741279
}
1275-
return new js.Block(assignments);
1280+
return wrapPhase('aliases', assignments);
12761281
}
12771282

12781283
/// Encodes the optional default values so that the runtime Function.apply

0 commit comments

Comments
 (0)