Ensure cacheIndexOf works correctly with boolean values.

Former-commit-id: 21f65952b14ddfff892a8c151545ad807a8ec9ef
This commit is contained in:
John-David Dalton
2013-08-25 01:39:18 -07:00
parent 2969290c63
commit d47cac563a
6 changed files with 27 additions and 16 deletions

View File

@@ -179,17 +179,17 @@
cache = cache.cache;
if (type == 'boolean' || value == null) {
return cache[value];
return cache[value] ? 0 : -1;
}
if (type != 'number' && type != 'string') {
type = 'object';
}
var key = type == 'number' ? value : keyPrefix + value;
cache = cache[type] || (cache[type] = {});
cache = (cache = cache[type]) && cache[key];
return type == 'object'
? (cache[key] && baseIndexOf(cache[key], value) > -1 ? 0 : -1)
: (cache[key] ? 0 : -1);
? (cache && baseIndexOf(cache, value) > -1 ? 0 : -1)
: (cache ? 0 : -1);
}
/**

View File

@@ -3,8 +3,8 @@
* Lo-Dash 1.3.1 (Custom Build) lodash.com/license | Underscore.js 1.5.1 underscorejs.org/LICENSE
* Build: `lodash -o ./dist/lodash.compat.js`
*/
;!function(){function n(n,t,e){e=(e||0)-1;for(var r=n?n.length:0;++e<r;)if(n[e]===t)return e;return-1}function t(t,e){var r=typeof e;if(t=t.k,"boolean"==r||e==m)return t[e];"number"!=r&&"string"!=r&&(r="object");var u="number"==r?e:x+e;return t=t[r]||(t[r]={}),"object"==r?t[u]&&-1<n(t[u],e)?0:-1:t[u]?0:-1}function e(n){var t=this.k,e=typeof n;if("boolean"==e||n==m)t[n]=y;else{"number"!=e&&"string"!=e&&(e="object");var r="number"==e?n:x+n,t=t[e]||(t[e]={});"object"==e?(t[r]||(t[r]=[])).push(n):t[r]=y
}}function r(n){return n.charCodeAt(0)}function u(n,t){var e=n.l,r=t.l;if(e!==r){if(e>r||typeof e=="undefined")return 1;if(e<r||typeof r=="undefined")return-1}return n.m-t.m}function o(n){var t=-1,r=n.length,u=n[0],o=n[r-1];if(u&&typeof u=="object"&&o&&typeof o=="object")return d;for(u=f(),u["false"]=u["null"]=u["true"]=u.undefined=d,o=f(),o.b=n,o.k=u,o.push=e;++t<r;)o.push(n[t]);return o}function a(n){return"\\"+X[n]}function i(){return b.pop()||[]}function f(){return _.pop()||{a:"",b:m,c:"",k:m,configurable:d,l:m,enumerable:d,"false":d,d:"",m:0,e:"",v:m,leading:d,g:"",maxWait:0,"null":d,number:m,z:m,push:m,h:m,string:m,i:"",trailing:d,"true":d,undefined:d,j:d,n:m,writable:d}
;!function(){function n(n,t,e){e=(e||0)-1;for(var r=n?n.length:0;++e<r;)if(n[e]===t)return e;return-1}function t(t,e){var r=typeof e;if(t=t.k,"boolean"==r||e==m)return t[e]?0:-1;"number"!=r&&"string"!=r&&(r="object");var u="number"==r?e:x+e;return t=(t=t[r])&&t[u],"object"==r?t&&-1<n(t,e)?0:-1:t?0:-1}function e(n){var t=this.k,e=typeof n;if("boolean"==e||n==m)t[n]=y;else{"number"!=e&&"string"!=e&&(e="object");var r="number"==e?n:x+n,t=t[e]||(t[e]={});"object"==e?(t[r]||(t[r]=[])).push(n):t[r]=y}}function r(n){return n.charCodeAt(0)
}function u(n,t){var e=n.l,r=t.l;if(e!==r){if(e>r||typeof e=="undefined")return 1;if(e<r||typeof r=="undefined")return-1}return n.m-t.m}function o(n){var t=-1,r=n.length,u=n[0],o=n[r-1];if(u&&typeof u=="object"&&o&&typeof o=="object")return d;for(u=f(),u["false"]=u["null"]=u["true"]=u.undefined=d,o=f(),o.b=n,o.k=u,o.push=e;++t<r;)o.push(n[t]);return o}function a(n){return"\\"+X[n]}function i(){return b.pop()||[]}function f(){return _.pop()||{a:"",b:m,c:"",k:m,configurable:d,l:m,enumerable:d,"false":d,d:"",m:0,e:"",v:m,leading:d,g:"",maxWait:0,"null":d,number:m,z:m,push:m,h:m,string:m,i:"",trailing:d,"true":d,undefined:d,j:d,n:m,writable:d}
}function l(n){return typeof n.toString!="function"&&typeof(n+"")=="string"}function c(){}function p(n){n.length=0,b.length<E&&b.push(n)}function s(n){var t=n.k;t&&s(t),n.b=n.k=n.l=n.object=n.number=n.string=n.n=m,_.length<E&&_.push(n)}function g(n,t,e){t||(t=0),typeof e=="undefined"&&(e=n?n.length:0);var r=-1;e=e-t||0;for(var u=Array(0>e?0:e);++r<e;)u[r]=n[t+r];return u}function h(e){function b(n){return n&&typeof n=="object"&&!qe(n)&&me.call(n,"__wrapped__")?n:new _(n)}function _(n,t){this.__chain__=!!t,this.__wrapped__=n
}function E(n,t,e,r,u){var o=n;if(e){if(o=e(o),typeof o!="undefined")return o;o=n}var a=dt(o);if(a){var f=ke.call(o);if(!V[f]||!Te.nodeClass&&l(o))return o;var c=qe(o)}if(!a||!t)return a?c?g(o):Ye({},o):o;switch(a=ze[f],f){case q:case K:return new a(+o);case J:case U:return new a(o);case H:return a(o.source,P.exec(o))}f=!r,r||(r=i()),u||(u=i());for(var s=r.length;s--;)if(r[s]==n)return u[s];return o=c?a(o.length):{},c&&(me.call(n,"index")&&(o.index=n.index),me.call(n,"input")&&(o.input=n.input)),r.push(n),u.push(o),(c?Xe:tr)(n,function(n,a){o[a]=E(n,t,e,r,u)
}),f&&(p(r),p(u)),o}function X(n,t,e){if(typeof n!="function")return Mt;if(typeof t=="undefined")return n;switch(e){case 1:return function(e){return n.call(t,e)};case 2:return function(e,r){return n.call(t,e,r)};case 3:return function(e,r,u){return n.call(t,e,r,u)};case 4:return function(e,r,u,o){return n.call(t,e,r,u,o)}}return Wt(n,t)}function Z(n,t,e,r){r=(r||0)-1;for(var u=n?n.length:0,o=[];++r<u;){var a=n[r];a&&typeof a=="object"&&(qe(a)||gt(a))?de.apply(o,t?a:Z(a,t,e)):e||o.push(a)}return o

8
dist/lodash.js vendored
View File

@@ -172,17 +172,17 @@
cache = cache.cache;
if (type == 'boolean' || value == null) {
return cache[value];
return cache[value] ? 0 : -1;
}
if (type != 'number' && type != 'string') {
type = 'object';
}
var key = type == 'number' ? value : keyPrefix + value;
cache = cache[type] || (cache[type] = {});
cache = (cache = cache[type]) && cache[key];
return type == 'object'
? (cache[key] && baseIndexOf(cache[key], value) > -1 ? 0 : -1)
: (cache[key] ? 0 : -1);
? (cache && baseIndexOf(cache, value) > -1 ? 0 : -1)
: (cache ? 0 : -1);
}
/**

4
dist/lodash.min.js vendored
View File

@@ -3,8 +3,8 @@
* Lo-Dash 1.3.1 (Custom Build) lodash.com/license | Underscore.js 1.5.1 underscorejs.org/LICENSE
* Build: `lodash modern -o ./dist/lodash.js`
*/
;!function(){function n(n,t,e){e=(e||0)-1;for(var r=n?n.length:0;++e<r;)if(n[e]===t)return e;return-1}function t(t,e){var r=typeof e;if(t=t.k,"boolean"==r||e==y)return t[e];"number"!=r&&"string"!=r&&(r="object");var u="number"==r?e:w+e;return t=t[r]||(t[r]={}),"object"==r?t[u]&&-1<n(t[u],e)?0:-1:t[u]?0:-1}function e(n){var t=this.k,e=typeof n;if("boolean"==e||n==y)t[n]=g;else{"number"!=e&&"string"!=e&&(e="object");var r="number"==e?n:w+n,t=t[e]||(t[e]={});"object"==e?(t[r]||(t[r]=[])).push(n):t[r]=g
}}function r(n){return n.charCodeAt(0)}function u(n,t){var e=n.l,r=t.l;if(e!==r){if(e>r||typeof e=="undefined")return 1;if(e<r||typeof r=="undefined")return-1}return n.m-t.m}function o(n){var t=-1,r=n.length,u=n[0],o=n[r-1];if(u&&typeof u=="object"&&o&&typeof o=="object")return m;for(u=f(),u["false"]=u["null"]=u["true"]=u.undefined=m,o=f(),o.b=n,o.k=u,o.push=e;++t<r;)o.push(n[t]);return o}function i(n){return"\\"+G[n]}function a(){return _.pop()||[]}function f(){return b.pop()||{b:y,k:y,configurable:m,l:y,enumerable:m,"false":m,m:0,leading:m,maxWait:0,"null":m,number:y,z:y,push:y,string:y,trailing:m,"true":m,undefined:m,n:y,writable:m}
;!function(){function n(n,t,e){e=(e||0)-1;for(var r=n?n.length:0;++e<r;)if(n[e]===t)return e;return-1}function t(t,e){var r=typeof e;if(t=t.k,"boolean"==r||e==y)return t[e]?0:-1;"number"!=r&&"string"!=r&&(r="object");var u="number"==r?e:w+e;return t=(t=t[r])&&t[u],"object"==r?t&&-1<n(t,e)?0:-1:t?0:-1}function e(n){var t=this.k,e=typeof n;if("boolean"==e||n==y)t[n]=g;else{"number"!=e&&"string"!=e&&(e="object");var r="number"==e?n:w+n,t=t[e]||(t[e]={});"object"==e?(t[r]||(t[r]=[])).push(n):t[r]=g}}function r(n){return n.charCodeAt(0)
}function u(n,t){var e=n.l,r=t.l;if(e!==r){if(e>r||typeof e=="undefined")return 1;if(e<r||typeof r=="undefined")return-1}return n.m-t.m}function o(n){var t=-1,r=n.length,u=n[0],o=n[r-1];if(u&&typeof u=="object"&&o&&typeof o=="object")return m;for(u=f(),u["false"]=u["null"]=u["true"]=u.undefined=m,o=f(),o.b=n,o.k=u,o.push=e;++t<r;)o.push(n[t]);return o}function i(n){return"\\"+G[n]}function a(){return _.pop()||[]}function f(){return b.pop()||{b:y,k:y,configurable:m,l:y,enumerable:m,"false":m,m:0,leading:m,maxWait:0,"null":m,number:y,z:y,push:y,string:y,trailing:m,"true":m,undefined:m,n:y,writable:m}
}function l(){}function c(n){n.length=0,_.length<k&&_.push(n)}function p(n){var t=n.k;t&&p(t),n.b=n.k=n.l=n.object=n.number=n.string=n.n=y,b.length<k&&b.push(n)}function s(n,t,e){t||(t=0),typeof e=="undefined"&&(e=n?n.length:0);var r=-1;e=e-t||0;for(var u=Array(0>e?0:e);++r<e;)u[r]=n[t+r];return u}function v(e){function _(n){if(!n||ke.call(n)!=K)return m;var t=n.valueOf,e=typeof t=="function"&&(e=ye(t))&&ye(e);return e?n==e||ye(n)==e:pt(n)}function b(n,t,e){if(!n||!V[typeof n])return n;t=t&&typeof e=="undefined"?t:et(t,e,3);
for(var r=-1,u=V[typeof n]&&Ke(n),o=u?u.length:0;++r<o&&(e=u[r],!(t(n[e],e,n)===false)););return n}function k(n,t,e){var r;if(!n||!V[typeof n])return n;t=t&&typeof e=="undefined"?t:et(t,e,3);for(r in n)if(t(n[r],r,n)===false)break;return n}function G(n,t,e){var r,u=n,o=u;if(!u)return o;for(var i=arguments,a=0,f=typeof e=="number"?2:i.length;++a<f;)if((u=i[a])&&V[typeof u])for(var l=-1,c=V[typeof u]&&Ke(u),p=c?c.length:0;++l<p;)r=c[l],"undefined"==typeof o[r]&&(o[r]=u[r]);return o}function J(n,t,e){var r,u=n,o=u;
if(!u)return o;var i=arguments,a=0,f=typeof e=="number"?2:i.length;if(3<f&&"function"==typeof i[f-2])var l=et(i[--f-1],i[f--],2);else 2<f&&"function"==typeof i[f-1]&&(l=i[--f]);for(;++a<f;)if((u=i[a])&&V[typeof u])for(var c=-1,p=V[typeof u]&&Ke(u),s=p?p.length:0;++c<s;)r=p[c],o[r]=l?l(o[r],u[r]):u[r];return o}function X(n){var t,e=[];if(!n||!V[typeof n])return e;for(t in n)me.call(n,t)&&e.push(t);return e}function Z(n){return n&&typeof n=="object"&&!Pe(n)&&me.call(n,"__wrapped__")?n:new nt(n)}function nt(n,t){this.__chain__=!!t,this.__wrapped__=n

View File

@@ -181,17 +181,17 @@
cache = cache.cache;
if (type == 'boolean' || value == null) {
return cache[value];
return cache[value] ? 0 : -1;
}
if (type != 'number' && type != 'string') {
type = 'object';
}
var key = type == 'number' ? value : keyPrefix + value;
cache = cache[type] || (cache[type] = {});
cache = (cache = cache[type]) && cache[key];
return type == 'object'
? (cache[key] && baseIndexOf(cache[key], value) > -1 ? 0 : -1)
: (cache[key] ? 0 : -1);
? (cache && baseIndexOf(cache, value) > -1 ? 0 : -1)
: (cache ? 0 : -1);
}
/**

View File

@@ -4004,6 +4004,17 @@
deepEqual(actual, [[2, 1], [1, 2]]);
});
test('should work with large arrays of boolean, `null`, and `undefined` values', function() {
var array = [],
expected = [true, false, null, undefined],
count = Math.ceil(largeArraySize / expected.length);
_.times(count, function() {
push.apply(array, expected);
});
deepEqual(_.uniq(array), expected);
});
test('should distinguish between numbers and numeric strings', function() {
var array = [],
expected = ['2', 2, Object('2'), Object(2)],