Reduce passing arguments to helper functions by converting them to arrays.

This commit is contained in:
John-David Dalton
2014-02-17 23:59:45 -08:00
parent 24edd68833
commit c634830b9f

View File

@@ -1077,10 +1077,16 @@
// `Function#bind` spec // `Function#bind` spec
// http://es5.github.io/#x15.3.4.5 // http://es5.github.io/#x15.3.4.5
if (partialArgs) { if (partialArgs) {
// avoid `arguments` object deoptimizations by using `slice` instead // avoid `arguments` object use disqualifying optimizations by
// of `Array.prototype.slice.call` and not assigning `arguments` to a // converting it to an array before passing it to `composeArgs`
// variable as a ternary expression var index = -1,
var args = composeArgs(partialArgs, partialHolders, arguments); length = arguments.length,
args = Array(length);
while (++index < length) {
args[index] = arguments[index];
}
args = composeArgs(partialArgs, partialHolders, args);
} }
// mimic the constructor's `return` behavior // mimic the constructor's `return` behavior
// http://es5.github.io/#x13.2.2 // http://es5.github.io/#x13.2.2
@@ -1296,27 +1302,29 @@
key = func; key = func;
function bound() { function bound() {
var thisBinding = isBind ? thisArg : this; var index = -1,
length = arguments.length,
args = Array(length);
while (++index < length) {
args[index] = arguments[index];
}
if (partialArgs) { if (partialArgs) {
var args = composeArgs(partialArgs, partialHolders, arguments); args = composeArgs(partialArgs, partialHolders, args);
} }
if (partialRightArgs) { if (partialRightArgs) {
args = composeArgsRight(partialRightArgs, partialRightHolders, args || arguments); args = composeArgsRight(partialRightArgs, partialRightHolders, args);
} }
if (isCurry) { if (isCurry && length < arity) {
var argsLength = arguments.length; bitmask |= PARTIAL_FLAG;
if (argsLength < arity) { bitmask &= ~PARTIAL_RIGHT_FLAG
args || (args = slice(arguments)); if (!isCurryBound) {
bitmask |= PARTIAL_FLAG; bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
bitmask &= ~PARTIAL_RIGHT_FLAG
if (!isCurryBound) {
bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
}
var newArity = nativeMax(0, arity - argsLength);
return baseCreateWrapper([func, bitmask, newArity, thisArg, args, null, []]);
} }
var newArity = nativeMax(0, arity - length);
return baseCreateWrapper([func, bitmask, newArity, thisArg, args, null, []]);
} }
args || (args = arguments); var thisBinding = isBind ? thisArg : this;
if (isBindKey) { if (isBindKey) {
func = thisBinding[key]; func = thisBinding[key];
} }
@@ -2791,14 +2799,13 @@
* // => [1, 1] * // => [1, 1]
*/ */
function pull(array) { function pull(array) {
var args = arguments, var argsIndex = 0,
argsIndex = 0, argsLength = arguments.length,
argsLength = args.length,
length = array ? array.length : 0; length = array ? array.length : 0;
while (++argsIndex < argsLength) { while (++argsIndex < argsLength) {
var index = -1, var index = -1,
value = args[argsIndex]; value = arguments[argsIndex];
while (++index < length) { while (++index < length) {
if (array[index] === value) { if (array[index] === value) {