Performance: Use identityHashCode for predecessors

This commit is contained in:
SirYwell 2025-05-07 16:51:02 +02:00
parent 800e3117c9
commit 1f402f5b9f
No known key found for this signature in database
2 changed files with 6 additions and 2 deletions

View file

@ -15,7 +15,7 @@ public sealed abstract class BinaryOperationNode extends Node permits AddNode, D
protected static int commutativeHashCode(BinaryOperationNode node) { protected static int commutativeHashCode(BinaryOperationNode node) {
int h = node.block().hashCode(); int h = node.block().hashCode();
// commutative operation: we want h(op(x, y)) == h(op(y, x)) // commutative operation: we want h(op(x, y)) == h(op(y, x))
h += 31 * (node.predecessor(LEFT).hashCode() ^ node.predecessor(RIGHT).hashCode()); h += 31 * (predecessorHash(node, LEFT) ^ predecessorHash(node, RIGHT));
return h; return h;
} }
@ -45,6 +45,6 @@ public sealed abstract class BinaryOperationNode extends Node permits AddNode, D
@Override @Override
public int hashCode() { public int hashCode() {
return (this.predecessor(LEFT).hashCode() * 31 + this.predecessor(RIGHT).hashCode()) ^ this.getClass().hashCode(); return (predecessorHash(this, LEFT) * 31 + predecessorHash(this, RIGHT)) ^ this.getClass().hashCode();
} }
} }

View file

@ -70,4 +70,8 @@ public sealed abstract class Node permits BinaryOperationNode, Block, ConstIntNo
public DebugInfo debugInfo() { public DebugInfo debugInfo() {
return debugInfo; return debugInfo;
} }
protected static int predecessorHash(Node node, int predecessor) {
return System.identityHashCode(node.predecessor(predecessor));
}
} }