Skip to content

Commit 849ece5

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
[dart2js] Use properties on Closure class for one common case
We can share the properties for single-argument closures by putting the properties on class Closure. (It is worthwhile to do this for zero and two argument closures, but we will need to add subclasses. That will be another CL). Change-Id: I30027965150f64200396df3d82140fb112b0899f Reviewed-on: https://dart-review.googlesource.com/c/83640 Reviewed-by: Sigmund Cherem <[email protected]> Commit-Queue: Stephen Adams <[email protected]>
1 parent fd5928e commit 849ece5

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

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

+28-11
Original file line numberDiff line numberDiff line change
@@ -979,15 +979,14 @@ class FragmentEmitter {
979979
if (cls.superclass == null) {
980980
// TODO(sra): What is this doing? Document or remove.
981981
properties
982-
.add(new js.Property(js.string("constructor"), classReference(cls)));
983-
properties
984-
.add(new js.Property(namer.operatorIs(cls.element), js.number(1)));
982+
.add(js.Property(js.string("constructor"), classReference(cls)));
983+
properties.add(js.Property(namer.operatorIs(cls.element), js.number(1)));
985984
}
986985

987986
allMethods.forEach((Method method) {
988987
emitInstanceMethod(method)
989988
.forEach((js.Expression name, js.Expression code) {
990-
var prop = new js.Property(name, code);
989+
var prop = js.Property(name, code);
991990
compiler.dumpInfoTask.registerEntityAst(method.element, prop);
992991
properties.add(prop);
993992
});
@@ -997,8 +996,16 @@ class FragmentEmitter {
997996
// Closures extend a common base class, so we can put properties on the
998997
// prototype for common values.
999998

999+
// Closures taking exactly one argument are common.
1000+
properties.add(js.Property(
1001+
js.string(namer.callCatchAllName),
1002+
js.quoteName(
1003+
namer.getNameForJsGetName(null, JsGetName.CALL_PREFIX1))));
1004+
properties.add(
1005+
js.Property(js.string(namer.requiredParameterField), js.number(1)));
1006+
10001007
// Most closures have no optional arguments.
1001-
properties.add(new js.Property(
1008+
properties.add(js.Property(
10021009
js.string(namer.defaultValuesField), new js.LiteralNull()));
10031010
}
10041011

@@ -1081,12 +1088,22 @@ class FragmentEmitter {
10811088
// complex cases. [forceAdd] might be true when this is fixed.
10821089
bool forceAdd = !method.isClosureCallMethod;
10831090

1084-
properties[js.string(namer.callCatchAllName)] = js.quoteName(
1085-
method.applyIndex == 0
1086-
? method.name
1087-
: method.parameterStubs[method.applyIndex - 1].name);
1088-
properties[js.string(namer.requiredParameterField)] =
1089-
js.number(method.requiredParameterCount);
1091+
// Common case of "call*": "call$1" is stored on the Closure class.
1092+
if (method.applyIndex != 0 ||
1093+
method.parameterStubs.isNotEmpty ||
1094+
method.requiredParameterCount != 1 ||
1095+
forceAdd) {
1096+
js.Name applyName = method.applyIndex == 0
1097+
? method.name
1098+
: method.parameterStubs[method.applyIndex - 1].name;
1099+
properties[js.string(namer.callCatchAllName)] =
1100+
js.quoteName(applyName);
1101+
}
1102+
// Common case of '1' is stored on the Closure class.
1103+
if (method.requiredParameterCount != 1 || forceAdd) {
1104+
properties[js.string(namer.requiredParameterField)] =
1105+
js.number(method.requiredParameterCount);
1106+
}
10901107

10911108
js.Expression defaultValues =
10921109
_encodeOptionalParameterDefaultValues(method);

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

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import 'package:js_runtime/shared/embedded_names.dart'
1818
INTERCEPTORS_BY_TAG,
1919
IS_HUNK_INITIALIZED,
2020
IS_HUNK_LOADED,
21+
JsGetName,
2122
LEAF_TAGS,
2223
MANGLED_GLOBAL_NAMES,
2324
MANGLED_NAMES,

0 commit comments

Comments
 (0)