mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Optimize _.omit for large arrays by leveraging _.difference which has optimizations for large arrays.
This commit is contained in:
36
dist/lodash.js
vendored
36
dist/lodash.js
vendored
@@ -2631,23 +2631,29 @@
|
||||
* // => { 'name': 'fred' }
|
||||
*/
|
||||
function omit(object, callback, thisArg) {
|
||||
var indexOf = getIndexOf(),
|
||||
isFunc = typeof callback == 'function',
|
||||
result = {};
|
||||
var result = {};
|
||||
if (typeof callback != 'function') {
|
||||
var props = [];
|
||||
forIn(object, function(value, key) {
|
||||
props.push(key);
|
||||
});
|
||||
props = difference(props, baseFlatten(arguments, true, false, 1));
|
||||
|
||||
if (isFunc) {
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
} else {
|
||||
var props = baseFlatten(arguments, true, false, 1);
|
||||
}
|
||||
forIn(object, function(value, key, object) {
|
||||
if (isFunc
|
||||
? !callback(value, key, object)
|
||||
: indexOf(props, key) < 0
|
||||
) {
|
||||
result[key] = value;
|
||||
var index = -1,
|
||||
length = props.length;
|
||||
|
||||
while (++index < length) {
|
||||
var key = props[index];
|
||||
result[key] = object[key];
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
forIn(object, function(value, key, object) {
|
||||
if (!callback(value, key, object)) {
|
||||
result[key] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user