Reviewers: Mads Ager,

Description:
Provide special case for f.bind(obj).

Function returned for generic case is extremely slow, does an allocation
per-call and is not Crankshaft friendly.

Please review this at http://codereview.chromium.org/6413018/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/v8natives.js


Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index 04444697d817a035c709ffcf9a044fb91bf3d81c..c502c2422065dfd3fd6ab31608d917ab240e0dc4 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -1141,26 +1141,30 @@ function FunctionBind(this_arg) { // Length is 1.
     }
   }
   var fn = this;
-  var result = function() {
-    // Combine the args we got from the bind call with the args
-    // given as argument to the invocation.
-    var argc = %_ArgumentsLength();
-    var args = new $Array(argc + argc_bound);
-    // Add bound arguments.
-    for (var i = 0; i < argc_bound; i++) {
-      args[i] = bound_args[i];
-    }
-    // Add arguments from call.
-    for (var i = 0; i < argc; i++) {
-      args[argc_bound + i] = %_Arguments(i);
-    }
-    // If this is a construct call we use a special runtime method
-    // to generate the actual object using the bound function.
-    if (%_IsConstructCall()) {
-      return %NewObjectFromBound(fn, args);
-    }
-    return fn.apply(this_arg, args);
-  };
+  if (argc_bound == 0) {
+    var result = function() { return fn.apply(this_arg, arguments); };
+  } else {
+    var result = function() {
+      // Combine the args we got from the bind call with the args
+      // given as argument to the invocation.
+      var argc = %_ArgumentsLength();
+      var args = new $Array(argc + argc_bound);
+      // Add bound arguments.
+      for (var i = 0; i < argc_bound; i++) {
+        args[i] = bound_args[i];
+      }
+      // Add arguments from call.
+      for (var i = 0; i < argc; i++) {
+        args[argc_bound + i] = %_Arguments(i);
+      }
+      // If this is a construct call we use a special runtime method
+      // to generate the actual object using the bound function.
+      if (%_IsConstructCall()) {
+        return %NewObjectFromBound(fn, args);
+      }
+      return fn.apply(this_arg, args);
+    };
+  }

   // We already have caller and arguments properties on functions,
   // which are non-configurable. It therefore makes no sence to


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to