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

Unified Diff: sdk/lib/_internal/compiler/js_lib/js_helper.dart

Issue 1032013002: dart2js: Optimize Function.apply for 0-3 argument calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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
Index: sdk/lib/_internal/compiler/js_lib/js_helper.dart
diff --git a/sdk/lib/_internal/compiler/js_lib/js_helper.dart b/sdk/lib/_internal/compiler/js_lib/js_helper.dart
index 92cae8e90fea146f7c6c6e5fe14bdc0d8e5873b9..0d0d854bf43e3224916a5b5c2e3065cab2e44969 100644
--- a/sdk/lib/_internal/compiler/js_lib/js_helper.dart
+++ b/sdk/lib/_internal/compiler/js_lib/js_helper.dart
@@ -1146,20 +1146,47 @@ class Primitives {
static applyFunctionWithPositionalArguments(Function function,
List positionalArguments) {
- int argumentCount = 0;
List arguments;
if (positionalArguments != null) {
if (JS('bool', '# instanceof Array', positionalArguments)) {
- arguments = positionalArguments;
+ arguments = JS('JSArray', '#', positionalArguments);
} else {
arguments = new List.from(positionalArguments);
}
- argumentCount = JS('int', '#.length', arguments);
} else {
arguments = [];
}
+ if (arguments.length == 0) {
+ String selectorName = JS_GET_NAME(JsGetName.CALL_PREFIX0);
+ if (JS('bool', '!!#[#]', function, selectorName)) {
+ return JS('', '#[#]()', function, selectorName);
+ }
+ } else if (arguments.length == 1) {
+ String selectorName = JS_GET_NAME(JsGetName.CALL_PREFIX1);
+ if (JS('bool', '!!#[#]', function, selectorName)) {
+ return JS('', '#[#](#)', function, selectorName, arguments[0]);
+ }
+ } else if (arguments.length == 2) {
+ String selectorName = JS_GET_NAME(JsGetName.CALL_PREFIX2);
+ if (JS('bool', '!!#[#]', function, selectorName)) {
+ return JS('', '#[#](#,#)', function, selectorName,
+ arguments[0], arguments[1]);
+ }
+ } else if (arguments.length == 3) {
+ String selectorName = JS_GET_NAME(JsGetName.CALL_PREFIX3);
+ if (JS('bool', '!!#[#]', function, selectorName)) {
+ return JS('', '#[#](#,#,#)', function, selectorName,
+ arguments[0], arguments[1], arguments[2]);
sra1 2015/03/25 03:16:29 I would not surprise me if the array bounds checks
floitsch 2015/03/25 22:58:30 I was sure I had tested it, but you are (unfortuna
+ }
+ }
+ return _genericApplyFunctionWithPositionalArguments(function, arguments);
+ }
+
+ static _genericApplyFunctionWithPositionalArguments(Function function,
+ List arguments) {
+ int argumentCount = arguments.length;
String selectorName =
'${JS_GET_NAME(JsGetName.CALL_PREFIX)}\$$argumentCount';
var jsFunction = JS('var', '#[#]', function, selectorName);
@@ -1168,13 +1195,13 @@ class Primitives {
jsFunction = JS('', '#["call*"]', interceptor);
if (jsFunction == null) {
- return functionNoSuchMethod(function, positionalArguments, null);
+ return functionNoSuchMethod(function, arguments, null);
}
ReflectionInfo info = new ReflectionInfo(jsFunction);
int maxArgumentCount = info.requiredParameterCount +
info.optionalParameterCount;
if (info.areOptionalParametersNamed || maxArgumentCount < argumentCount) {
- return functionNoSuchMethod(function, positionalArguments, null);
+ return functionNoSuchMethod(function, arguments, null);
}
arguments = new List.from(arguments);
for (int pos = argumentCount; pos < maxArgumentCount; pos++) {
« no previous file with comments | « pkg/compiler/lib/src/js_backend/namer.dart ('k') | sdk/lib/_internal/compiler/js_lib/shared/embedded_names.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698