jenkins-bot has submitted this change and it was merged.
Change subject: Recurse more frugally in oo.compare
......................................................................
Recurse more frugally in oo.compare
Previously, oo.compare called itself twice on every sub-structure, thrice on
every sub-sub-structure, and (n+1) times on every sub^n-structure.
Change-Id: I04a7e5aeb21fc9c6bba2d329e2d458533f67e28a
---
M src/core.js
M tests/unit/core.test.js
2 files changed, 28 insertions(+), 3 deletions(-)
Approvals:
Ori.livneh: Looks good to me, approved
jenkins-bot: Verified
diff --git a/src/core.js b/src/core.js
index 33333dc..29002e7 100644
--- a/src/core.js
+++ b/src/core.js
@@ -305,7 +305,7 @@
( aType === 'string' || aType === 'number' ||
aType === 'boolean' ) &&
aValue !== bValue
) ||
- ( aValue === Object( aValue ) && !oo.compare( aValue,
bValue, asymmetrical ) ) ) {
+ ( aValue === Object( aValue ) && !oo.compare( aValue,
bValue, true ) ) ) {
return false;
}
}
diff --git a/tests/unit/core.test.js b/tests/unit/core.test.js
index 1141f52..5e74341 100644
--- a/tests/unit/core.test.js
+++ b/tests/unit/core.test.js
@@ -630,8 +630,8 @@
);
} );
- QUnit.test( 'compare( Object, Object, Boolean asymmetrical )', 4,
function ( assert ) {
- var x, y, z;
+ QUnit.test( 'compare( Object, Object, Boolean asymmetrical )', 5,
function ( assert ) {
+ var x, y, z, i, depth, compare;
x = {
foo: [ true, 42 ],
@@ -677,6 +677,31 @@
true,
'A subset of B with sparse array'
);
+
+ x = null;
+ y = null;
+ depth = 15;
+ for ( i = 0; i < depth; i++ ) {
+ x = [ x, x ];
+ y = [ y, y ];
+ }
+ compare = oo.compare;
+ try {
+ oo.compare = function () {
+ oo.compare.callCount += 1;
+ return compare.apply( null, arguments );
+ };
+ oo.compare.callCount = 0;
+ oo.compare( x, y );
+ /**jshint bitwise: true */
+ assert.strictEqual(
+ oo.compare.callCount,
+ Math.pow( 2, depth + 1 ) - 2,
+ 'Efficient depth recursion'
+ );
+ } finally {
+ oo.compare = compare;
+ }
} );
QUnit.test( 'copy( source )', 14, function ( assert ) {
--
To view, visit https://gerrit.wikimedia.org/r/192861
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I04a7e5aeb21fc9c6bba2d329e2d458533f67e28a
Gerrit-PatchSet: 1
Gerrit-Project: oojs/core
Gerrit-Branch: master
Gerrit-Owner: Divec <[email protected]>
Gerrit-Reviewer: Divec <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits