mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
assert,util: improve deep equal comparison performance
This is mainly a performance improvement for a lot of simple cases. Diverging elements are detected earlier and equal entries are partially also detected faster. A small correctness patch is also included where recursions now stop as soon as either side has a circular structure. Before, both sides had to have a circular structure at the specific comparison which could have caused more checks that likely fail at a later point. Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de> PR-URL: https://github.com/nodejs/node/pull/46593 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
1 parent
abba45e120
commit
7f85a2cb6f
4 files changed
+176
-133
No files matched your search
@@ -419,21 +419,33 @@ assertNotDeepOrStrict(
|
||||
// GH-14441. Circular structures should be consistent
|
||||
{
|
||||
const a = {};
|
||||
const b = {};
|
||||
a.a = a;
|
||||
|
||||
const b = {};
|
||||
b.a = {};
|
||||
b.a.a = a;
|
||||
assertDeepAndStrictEqual(a, b);
|
||||
|
||||
assertNotDeepOrStrict(a, b);
|
||||
}
|
||||
|
||||
{
|
||||
const a = {};
|
||||
a.a = a;
|
||||
const b = {};
|
||||
b.a = b;
|
||||
const c = {};
|
||||
c.a = a;
|
||||
assertNotDeepOrStrict(b, c);
|
||||
}
|
||||
|
||||
{
|
||||
const a = new Set();
|
||||
const b = new Set();
|
||||
const c = new Set();
|
||||
a.add(a);
|
||||
const b = new Set();
|
||||
b.add(b);
|
||||
const c = new Set();
|
||||
c.add(a);
|
||||
assertDeepAndStrictEqual(b, c);
|
||||
assertNotDeepOrStrict(b, c);
|
||||
}
|
||||
|
||||
// https://github.com/nodejs/node-v0.x-archive/pull/7178
|
||||
|
||||
Reference in new issue
Block a user