Skip to content

Commit

Permalink
non-terrible performance version suggested by @blerner
Browse files Browse the repository at this point in the history
  • Loading branch information
jpolitz committed Oct 7, 2016
1 parent d77c5a0 commit f9c7e5a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/js/base/runtime.js
Expand Up @@ -1842,13 +1842,14 @@ function (Namespace, jsnums, codePoint, seedrandom, util) {
cache.left.push(obj1);
cache.right.push(obj2);
cache.equal.push(thisRuntime.ffi.equal);
return cache.equal.length;
}
function equalHelp() {
var current, curLeft, curRight;
while (toCompare.stack.length > 0 && !thisRuntime.ffi.isNotEqual(toCompare.curAns)) {
current = toCompare.stack.pop();
if(current.setCache) {
setCachePair(current.left, current.right, toCompare.curAns);
cache.equal[current.index - 1] = toCompare.curAns;

This comment has been minimized.

Copy link
@blerner

blerner Oct 7, 2016

Member

Could you delete the setCachePair function, too?

continue;
}
curLeft = current.left;
Expand Down Expand Up @@ -1895,8 +1896,8 @@ function (Namespace, jsnums, codePoint, seedrandom, util) {
toCompare.curAns = curPair
continue;
} else {
cachePair(curLeft, curRight);
toCompare.stack.push({ setCache: true, left: curLeft, right: curRight });
var index = cachePair(curLeft, curRight);
toCompare.stack.push({ setCache: true, index: index, left: curLeft, right: curRight });

This comment has been minimized.

Copy link
@blerner

blerner Oct 7, 2016

Member

You could ditch the setCache field entirely, and make the check below just be if current.index !== undefined

if (isRef(curLeft) && isRef(curRight)) {
if (alwaysFlag && !(isRefFrozen(curLeft) && isRefFrozen(curRight))) { // In equal-always, non-identical refs are not equal
toCompare.curAns = thisRuntime.ffi.notEqual.app(current.path, curLeft, curRight); // We would've caught identical refs already
Expand Down Expand Up @@ -2058,10 +2059,9 @@ function (Namespace, jsnums, codePoint, seedrandom, util) {
for(var i = 0; i < toCompare.stack.length; i++) {
var current = toCompare.stack[i];
if(current.setCache) {
setCachePair(current.left, current.right, $ans);
cache.equal[current.index - 1] = $ans;
}
}
setCachePair(left, right, $ans);
toCompare = stackOfToCompare.pop();
return $ans;
}
Expand Down

0 comments on commit f9c7e5a

Please sign in to comment.