From a97836a175c6d0bc03533cfc66e051f70cc5a4f8 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sun, 6 Dec 2009 12:55:43 -0500 Subject: [PATCH] a couple of grayrest's speed improvements for _.isEqual --- underscore.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/underscore.js b/underscore.js index ba8450011..d76efb223 100644 --- a/underscore.js +++ b/underscore.js @@ -420,12 +420,16 @@ if (atype != btype) return false; // Basic equality test (watch out for coercions). if (a == b) return true; + // Check dates' integer values. + if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime(); // One of them implements an isEqual()? if (a.isEqual) return a.isEqual(b); // Both are NaN? if (_.isNumber(a) && _.isNumber(b) && isNaN(a) && isNaN(b)) return true; // If a is not an object by this point, we can't handle it. if (atype !== 'object') return false; + // Check for different array lengths before comparing contents. + if (!_.isUndefined(a.length) && a.length !== b.length) return false; // Nothing else worked, deep compare the contents. var aKeys = _.keys(a), bKeys = _.keys(b); // Different object sizes?