Optimize _.omit for large arrays by leveraging _.difference which has optimizations for large arrays.

This commit is contained in:
John-David Dalton
2013-11-06 20:45:24 -08:00
parent 7e7b129822
commit 3dd3af4a73
7 changed files with 108 additions and 85 deletions

View File

@@ -1594,15 +1594,20 @@
* // => { 'name': 'fred' }
*/
function omit(object) {
var indexOf = getIndexOf(),
props = baseFlatten(arguments, true, false, 1),
var props = [];
forIn(object, function(value, key) {
props.push(key);
});
props = difference(props, baseFlatten(arguments, true, false, 1));
var index = -1,
length = props.length,
result = {};
forIn(object, function(value, key) {
if (indexOf(props, key) < 0) {
result[key] = value;
}
});
while (++index < length) {
var key = props[index];
result[key] = object[key];
}
return result;
}
@@ -1667,9 +1672,9 @@
result = {};
while (++index < length) {
var prop = props[index];
if (prop in object) {
result[prop] = object[prop];
var key = props[index];
if (key in object) {
result[key] = object[key];
}
}
return result;