Cleanup compareAscending and createBound.

Former-commit-id: e783a68666aaea16d917fa1db74d2092e5dcaa9a
This commit is contained in:
John-David Dalton
2013-08-09 22:47:55 -07:00
parent fca8da118e
commit c97fc370cd
9 changed files with 277 additions and 267 deletions

View File

@@ -108,19 +108,16 @@
* @returns {Number} Returns the sort order indicator of `1` or `-1`.
*/
function compareAscending(a, b) {
var ai = a.index,
bi = b.index;
a = a.criteria;
b = b.criteria;
var ac = a.criteria;
bc = b.criteria;
// ensure a stable sort in V8 and other engines
// http://code.google.com/p/v8/issues/detail?id=90
if (a !== b) {
if (a > b || typeof a == 'undefined') {
if (ac !== bc) {
if (ac > bc || typeof ac == 'undefined') {
return 1;
}
if (a < b || typeof b == 'undefined') {
if (ac < bc || typeof bc == 'undefined') {
return -1;
}
}
@@ -128,7 +125,7 @@
// `Array#sort` implementation that causes it, under certain circumstances,
// to return the same value for `a` and `b`.
// See https://github.com/jashkenas/underscore/pull/1247
return ai < bi ? -1 : (ai > bi ? 1 : 0);
return a.index - b.index;
}
/**
@@ -604,8 +601,9 @@
* 1 - `_.bind`
* 2 - `_.bindKey`
* 4 - `_.curry`
* 8 - `_.partial`
* 16 - `_.partialRight`
* 8 - `_.curry` (bound)
* 16 - `_.partial`
* 32 - `_.partialRight`
* @param {Array} [partialArgs] An array of arguments to prepend to those
* provided to the new function.
* @param {Array} [partialRightArgs] An array of arguments to append to those
@@ -618,8 +616,9 @@
var isBind = bitmask & 1,
isBindKey = bitmask & 2,
isCurry = bitmask & 4,
isPartial = bitmask & 8,
isPartialRight = bitmask & 16;
isCurryBound = bitmask & 8,
isPartial = bitmask & 16,
isPartialRight = bitmask & 32;
if (!isBindKey && !isFunction(func)) {
throw new TypeError;
@@ -646,7 +645,8 @@
push.apply(args, partialRightArgs);
}
if (isCurry && args.length < arity) {
return createBound(func, 12, args, null, null, arity);
bitmask |= 16 & ~32
return createBound(func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity);
}
if (isBindKey) {
func = thisBinding[key];
@@ -3450,7 +3450,7 @@
* // => 'hi moe'
*/
function bind(func, thisArg) {
return createBound(func, 9, nativeSlice.call(arguments, 2), null, thisArg);
return createBound(func, 17, nativeSlice.call(arguments, 2), null, thisArg);
}
/**
@@ -3853,7 +3853,7 @@
* // => 'hi moe'
*/
function partial(func) {
return createBound(func, 8, nativeSlice.call(arguments, 1));
return createBound(func, 16, nativeSlice.call(arguments, 1));
}
/**