mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 01:57:50 +00:00
Reduce deep _.clone array iteration and add _.each dependency.
Former-commit-id: 3cb599d294a693974483b892748e6f60186d0c50
This commit is contained in:
18
lodash.js
18
lodash.js
@@ -1065,7 +1065,6 @@
|
||||
case regexpClass:
|
||||
return ctor(value.source, reFlags.exec(value));
|
||||
}
|
||||
|
||||
// check for circular references and return corresponding clone
|
||||
stackA || (stackA = []);
|
||||
stackB || (stackB = []);
|
||||
@@ -1076,9 +1075,8 @@
|
||||
return stackB[length];
|
||||
}
|
||||
}
|
||||
|
||||
// init cloned object
|
||||
var result = isArr ? ctor(length = value.length) : {};
|
||||
var result = isArr ? ctor(value.length) : {};
|
||||
|
||||
// add the source value to the stack of traversed objects
|
||||
// and associate it with its clone
|
||||
@@ -1086,16 +1084,10 @@
|
||||
stackB.push(result);
|
||||
|
||||
// recursively populate clone (susceptible to call stack limits)
|
||||
if (isArr) {
|
||||
var index = -1;
|
||||
while (++index < length) {
|
||||
result[index] = clone(value[index], deep, null, stackA, stackB);
|
||||
}
|
||||
} else {
|
||||
forOwn(value, function(objValue, key) {
|
||||
result[key] = clone(objValue, deep, null, stackA, stackB);
|
||||
});
|
||||
}
|
||||
(isArr ? forEach : forOwn)(value, function(objValue, key) {
|
||||
result[key] = clone(objValue, deep, null, stackA, stackB);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user