Avoid double cloning for the common case in _.omit.

This commit is contained in:
John-David Dalton
2016-11-15 18:18:19 -08:00
parent 9a02bd5fc7
commit 5bc9e6b8bd

View File

@@ -13460,16 +13460,16 @@
if (object == null) { if (object == null) {
return result; return result;
} }
var bitmask = CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG; var isDeep = false;
paths = arrayMap(paths, function(path) { paths = arrayMap(paths, function(path) {
path = castPath(path, object); path = castPath(path, object);
bitmask |= (path.length > 1 ? CLONE_DEEP_FLAG : 0); isDeep || (isDeep = path.length > 1);
return path; return path;
}); });
copyObject(object, getAllKeysIn(object), result); copyObject(object, getAllKeysIn(object), result);
result = baseClone(result, bitmask); if (isDeep) {
result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG);
}
var length = paths.length; var length = paths.length;
while (length--) { while (length--) {
baseUnset(result, paths[length]); baseUnset(result, paths[length]);