From 529c5b8abfa6679b29671edb7e02656304dd873a Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 29 Nov 2012 20:57:13 -0800 Subject: [PATCH] Use `forIn` in `_.isEqual` instead of `forOwn`. Former-commit-id: dd057e421be029d67cd293b733ee1cfee2b7715f --- lodash.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lodash.js b/lodash.js index 077f208c0..08abcde27 100644 --- a/lodash.js +++ b/lodash.js @@ -1356,19 +1356,24 @@ } return result; } - // deep compare objects - forOwn(a, function(value, key) { - // count the number of properties. - size++; - // deep compare each property value. - return (result = hasOwnProperty.call(b, key) && isEqual(value, b[key], stackA, stackB)); + // deep compare objects using `forIn`, instead of `forOwn`, to avoid `Object.keys` + // which, in this case, is more costly + forIn(a, function(value, key, a) { + if (hasOwnProperty.call(a, key)) { + // count the number of properties. + size++; + // deep compare each property value. + return (result = hasOwnProperty.call(b, key) && isEqual(value, b[key], stackA, stackB)); + } }); if (result) { // ensure both objects have the same number of properties - forOwn(b, function() { - // `size` will be `-1` if `b` has more properties than `a` - return (result = --size > -1); + forIn(b, function(value, key, b) { + if (hasOwnProperty.call(b, key)) { + // `size` will be `-1` if `b` has more properties than `a` + return (result = --size > -1); + } }); } return result;