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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart

Issue 2831493003: dart2js: --fast-startup: cache prototypes in local in tear-off setup (Closed)
Patch Set: add comments Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart2js.js_emitter.startup_emitter.model_emitter; 5 part of dart2js.js_emitter.startup_emitter.model_emitter;
6 6
7 /// The name of the property that stores the tear-off getter on a static 7 /// The name of the property that stores the tear-off getter on a static
8 /// function. 8 /// function.
9 /// 9 ///
10 /// This property is only used when isolates are used. 10 /// This property is only used when isolates are used.
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 } 1019 }
1020 1020
1021 return js.js.statement( 1021 return js.js.statement(
1022 ''' 1022 '''
1023 installTearOff(#container, #getterName, #isStatic, #isIntercepted, 1023 installTearOff(#container, #getterName, #isStatic, #isIntercepted,
1024 #requiredParameterCount, #optionalParameterDefaultValues, 1024 #requiredParameterCount, #optionalParameterDefaultValues,
1025 #callNames, #funsOrNames, #funType)''', 1025 #callNames, #funsOrNames, #funType)''',
1026 { 1026 {
1027 "container": container, 1027 "container": container,
1028 "getterName": js.quoteName(method.tearOffName), 1028 "getterName": js.quoteName(method.tearOffName),
1029 "isStatic": new js.LiteralBool(method.isStatic), 1029 // 'Truthy' values are ok for `isStatic` and `isIntercepted`.
1030 "isIntercepted": new js.LiteralBool(isIntercepted), 1030 "isStatic": js.number(method.isStatic ? 1 : 0),
1031 "isIntercepted": js.number(isIntercepted ? 1 : 0),
1031 "requiredParameterCount": js.number(requiredParameterCount), 1032 "requiredParameterCount": js.number(requiredParameterCount),
1032 "optionalParameterDefaultValues": optionalParameterDefaultValues, 1033 "optionalParameterDefaultValues": optionalParameterDefaultValues,
1033 "callNames": callNameArray, 1034 "callNames": callNameArray,
1034 "funsOrNames": funsOrNamesArray, 1035 "funsOrNames": funsOrNamesArray,
1035 "funType": method.functionType, 1036 "funType": method.functionType,
1036 }); 1037 });
1037 } 1038 }
1038 1039
1039 /// Wraps the statement in a named function to that it shows up as a unit in 1040 /// Wraps the statement in a named function to that it shows up as a unit in
1040 /// profiles. 1041 /// profiles.
1041 // TODO(sra): Should this be conditional? 1042 // TODO(sra): Should this be conditional?
1042 js.Statement wrapPhase(String name, js.Statement statement) { 1043 js.Statement wrapPhase(String name, js.Statement statement) {
1043 return js.js.statement('(function #(){#})();', [name, statement]); 1044 return js.js.statement('(function #(){#})();', [name, statement]);
1044 } 1045 }
1045 1046
1046 /// Emits the section that installs tear-off getters. 1047 /// Emits the section that installs tear-off getters.
1047 js.Statement emitInstallTearOffs(Fragment fragment) { 1048 js.Statement emitInstallTearOffs(Fragment fragment) {
1048 List<js.Statement> inits = <js.Statement>[]; 1049 List<js.Statement> inits = <js.Statement>[];
1050 js.Expression temp;
1049 1051
1050 for (Library library in fragment.libraries) { 1052 for (Library library in fragment.libraries) {
1051 for (StaticMethod method in library.statics) { 1053 for (StaticMethod method in library.statics) {
1052 // TODO(floitsch): can there be anything else than a StaticDartMethod? 1054 // TODO(floitsch): can there be anything else than a StaticDartMethod?
1053 if (method is StaticDartMethod) { 1055 if (method is StaticDartMethod) {
1054 if (method.needsTearOff) { 1056 if (method.needsTearOff) {
1055 Holder holder = method.holder; 1057 Holder holder = method.holder;
1056 inits.add( 1058 inits.add(
1057 emitInstallTearOff(new js.VariableUse(holder.name), method)); 1059 emitInstallTearOff(new js.VariableUse(holder.name), method));
1058 } 1060 }
1059 } 1061 }
1060 } 1062 }
1061 for (Class cls in library.classes) { 1063 for (Class cls in library.classes) {
1062 for (InstanceMethod method in cls.methods) { 1064 var methods = cls.methods.where((m) => m.needsTearOff).toList();
1063 if (method.needsTearOff) { 1065 js.Expression container = js.js("#.prototype", classReference(cls));
1064 js.Expression container = js.js("#.prototype", classReference(cls)); 1066 js.Expression reference = container;
1065 inits.add(emitInstallTearOff(container, method)); 1067 if (methods.length > 1) {
1068 if (temp == null) {
1069 inits.add(js.js.statement('var _;'));
1070 temp = js.js('_');
1066 } 1071 }
1072 // First call uses assignment to temp to cache the container.
1073 reference = js.js('# = #', [temp, container]);
1074 }
1075 for (InstanceMethod method in methods) {
1076 inits.add(emitInstallTearOff(reference, method));
1077 reference = temp; // Second and subsequent calls use temp.
1067 } 1078 }
1068 } 1079 }
1069 } 1080 }
1070 return wrapPhase('installTearOffs', new js.Block(inits)); 1081 return wrapPhase('installTearOffs', new js.Block(inits));
1071 } 1082 }
1072 1083
1073 /// Emits the constants section. 1084 /// Emits the constants section.
1074 js.Statement emitConstants(Fragment fragment) { 1085 js.Statement emitConstants(Fragment fragment) {
1075 List<js.Statement> assignments = <js.Statement>[]; 1086 List<js.Statement> assignments = <js.Statement>[];
1076 for (Constant constant in fragment.constants) { 1087 for (Constant constant in fragment.constants) {
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 } 1445 }
1435 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", 1446 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);",
1436 js.objectLiteral(interceptorsByTag))); 1447 js.objectLiteral(interceptorsByTag)));
1437 statements.add( 1448 statements.add(
1438 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags))); 1449 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags)));
1439 statements.addAll(subclassAssignments); 1450 statements.addAll(subclassAssignments);
1440 1451
1441 return wrapPhase('nativeSupport', new js.Block(statements)); 1452 return wrapPhase('nativeSupport', new js.Block(statements));
1442 } 1453 }
1443 } 1454 }
OLDNEW
« 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