mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +00:00
Optimize _.contains and _.omit.
Former-commit-id: f1d7b5699bae6de90d880fe593531f7d3772924e
This commit is contained in:
15
lodash.js
15
lodash.js
@@ -1743,7 +1743,7 @@
|
|||||||
forIn(object, function(value, key, object) {
|
forIn(object, function(value, key, object) {
|
||||||
if (isFunc
|
if (isFunc
|
||||||
? !callback(value, key, object)
|
? !callback(value, key, object)
|
||||||
: indexOf(props, key) < 0
|
: indexOf(props, key, 1) < 0
|
||||||
) {
|
) {
|
||||||
result[key] = value;
|
result[key] = value;
|
||||||
}
|
}
|
||||||
@@ -1868,9 +1868,16 @@
|
|||||||
* // => true
|
* // => true
|
||||||
*/
|
*/
|
||||||
function contains(collection, target) {
|
function contains(collection, target) {
|
||||||
return toString.call(collection) == stringClass
|
var length = collection ? collection.length : 0;
|
||||||
? collection.indexOf(target) > -1
|
if (length === +length) {
|
||||||
: some(collection, function(value) { return value === target; });
|
return (toString.call(collection) == stringClass
|
||||||
|
? collection.indexOf(target)
|
||||||
|
: indexOf(collection, target)
|
||||||
|
) > -1;
|
||||||
|
}
|
||||||
|
return some(collection, function(value) {
|
||||||
|
return value === target;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
22
perf/perf.js
22
perf/perf.js
@@ -512,6 +512,28 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
suites.push(
|
||||||
|
Benchmark.Suite('`_.contains` iterating an array')
|
||||||
|
.add('Lo-Dash', '\
|
||||||
|
lodash.contains(numbers, 19)'
|
||||||
|
)
|
||||||
|
.add('Underscore', '\
|
||||||
|
_.contains(numbers, 19)'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
suites.push(
|
||||||
|
Benchmark.Suite('`_.contains` iterating an object')
|
||||||
|
.add('Lo-Dash', '\
|
||||||
|
lodash.contains(object, 19)'
|
||||||
|
)
|
||||||
|
.add('Underscore', '\
|
||||||
|
_.contains(object, 19)'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
suites.push(
|
suites.push(
|
||||||
Benchmark.Suite('`_.countBy` with `callback` iterating an array')
|
Benchmark.Suite('`_.countBy` with `callback` iterating an array')
|
||||||
.add('Lo-Dash', '\
|
.add('Lo-Dash', '\
|
||||||
|
|||||||
Reference in New Issue
Block a user