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

Unified Diff: sdk/lib/js/dart2js/js_dart2js.dart

Issue 1152673003: dart:js - speed up constructor calls with few arguments. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/js/dart2js/js_dart2js.dart
diff --git a/sdk/lib/js/dart2js/js_dart2js.dart b/sdk/lib/js/dart2js/js_dart2js.dart
index 6de50320ae1f5770d1a63cd21d13b48a083f50aa..849de82658db6c3982128d4d6d593c3fc165b4fb 100644
--- a/sdk/lib/js/dart2js/js_dart2js.dart
+++ b/sdk/lib/js/dart2js/js_dart2js.dart
@@ -141,6 +141,39 @@ class JsObject {
if (arguments == null) {
return _wrapToDart(JS('', 'new #()', constr));
}
+
+ if (JS('bool', '# instanceof Array', arguments)) {
+ int argumentCount = JS('int', '#.length', arguments);
+ switch (argumentCount) {
+ case 0:
+ return _wrapToDart(JS('', 'new #()', constr));
+
+ case 1:
+ var arg0 = _convertToJS(JS('', '#[0]', arguments));
+ return _wrapToDart(JS('', 'new #(#)', constr, arg0));
+
+ case 2:
+ var arg0 = _convertToJS(JS('', '#[0]', arguments));
+ var arg1 = _convertToJS(JS('', '#[1]', arguments));
+ return _wrapToDart(JS('', 'new #(#, #)', constr, arg0, arg1));
+
+ case 3:
+ var arg0 = _convertToJS(JS('', '#[0]', arguments));
+ var arg1 = _convertToJS(JS('', '#[1]', arguments));
+ var arg2 = _convertToJS(JS('', '#[2]', arguments));
+ return _wrapToDart(
+ JS('', 'new #(#, #, #)', constr, arg0, arg1, arg2));
+
+ case 4:
+ var arg0 = _convertToJS(JS('', '#[0]', arguments));
+ var arg1 = _convertToJS(JS('', '#[1]', arguments));
+ var arg2 = _convertToJS(JS('', '#[2]', arguments));
+ var arg3 = _convertToJS(JS('', '#[3]', arguments));
+ return _wrapToDart(
+ JS('', 'new #(#, #, #, #)', constr, arg0, arg1, arg2, arg3));
+ }
+ }
+
// The following code solves the problem of invoking a JavaScript
// constructor with an unknown number arguments.
// First bind the constructor to the argument list using bind.apply().
@@ -154,9 +187,16 @@ class JsObject {
JS('String', 'String(#)', factoryFunction);
// This could return an UnknownJavaScriptObject, or a native
// object for which there is an interceptor
- var jsObj = JS('JavaScriptObject', 'new #()', factoryFunction);
+ var jsObj = JS('', 'new #()', factoryFunction);
return _wrapToDart(jsObj);
+
+ // TODO(sra): Investigate:
+ //
+ // var jsObj = JS('', 'Object.create(#.prototype)', constr);
+ // JS('', '#.apply(#, #)', constr, jsObj,
+ // []..addAll(arguments.map(_convertToJS)));
+ // return _wrapToDart(jsObj);
}
/**
@@ -510,25 +550,28 @@ dynamic _convertToJS(dynamic o) {
// `undefined` in Javascprit). See dartbug.com/20305 for details.
if (o == null || o is String || o is num || o is bool) {
return o;
- } else if (o is Blob || o is Event || o is KeyRange || o is ImageData
- || o is Node || o is TypedData || o is Window) {
+ }
+ if (o is JsObject) {
+ return o._jsObject;
+ }
+ if (o is Blob || o is Event || o is KeyRange || o is ImageData || o is Node ||
+ o is TypedData || o is Window) {
return o;
- } else if (o is DateTime) {
+ }
+ if (o is DateTime) {
return Primitives.lazyAsJsDate(o);
- } else if (o is JsObject) {
- return o._jsObject;
- } else if (o is Function) {
+ }
+ if (o is Function) {
return _getJsProxy(o, _JS_FUNCTION_PROPERTY_NAME, (o) {
var jsFunction = _convertDartFunction(o);
// set a property on the JS closure referencing the Dart closure
_defineProperty(jsFunction, _DART_CLOSURE_PROPERTY_NAME, o);
return jsFunction;
});
- } else {
- var ctor = _dartProxyCtor;
- return _getJsProxy(o, _JS_OBJECT_PROPERTY_NAME,
- (o) => JS('', 'new #(#)', ctor, o));
}
+ var ctor = _dartProxyCtor;
+ return _getJsProxy(o, _JS_OBJECT_PROPERTY_NAME,
+ (o) => JS('', 'new #(#)', ctor, o));
}
Object _getJsProxy(o, String propertyName, createProxy(o)) {
@@ -567,13 +610,13 @@ JsObject _wrapToDart(o) {
if (JS('bool', 'typeof # == "function"', o)) {
return _getDartProxy(o, _DART_CLOSURE_PROPERTY_NAME,
(o) => new JsFunction._fromJs(o));
- } else if (JS('bool', '# instanceof Array', o)) {
+ }
+ if (JS('bool', '# instanceof Array', o)) {
return _getDartProxy(o, _DART_OBJECT_PROPERTY_NAME,
(o) => new JsArray._fromJs(o));
- } else {
- return _getDartProxy(o, _DART_OBJECT_PROPERTY_NAME,
- (o) => new JsObject._fromJs(o));
}
+ return _getDartProxy(o, _DART_OBJECT_PROPERTY_NAME,
+ (o) => new JsObject._fromJs(o));
}
Object _getDartProxy(o, String propertyName, createProxy(o)) {
« 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