From 9aa70d3a0ac6b8c4f587192d8e4296963dd97a13 Mon Sep 17 00:00:00 2001 From: Davy Landman Date: Mon, 15 Jan 2024 14:51:45 +0100 Subject: [PATCH] Using less expensive equals compare --- .../PersistentHashIndexedBinaryRelation.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/usethesource/vallang/impl/persistent/PersistentHashIndexedBinaryRelation.java b/src/main/java/io/usethesource/vallang/impl/persistent/PersistentHashIndexedBinaryRelation.java index 860f7ef0..f1b0464f 100644 --- a/src/main/java/io/usethesource/vallang/impl/persistent/PersistentHashIndexedBinaryRelation.java +++ b/src/main/java/io/usethesource/vallang/impl/persistent/PersistentHashIndexedBinaryRelation.java @@ -644,9 +644,15 @@ else if (values instanceof Set) { else { throw new IllegalArgumentException("Unexpected map entry"); } + // to avoid recalculating `lhs` next time we see it, we mark it as done. + // so that the next time we come across if on the rhs, we know the range is + // already the transitive closure. + // We add it before we've done it, just to avoid scheduling + // when it occurs during the depth scan for lhs. + done.add(lhs); IValue rhs; while ((rhs = todo.poll()) != null) { - if (rhs.equals(lhs)) { + if (lhs == rhs) { // no need to handle continue; } @@ -657,10 +663,6 @@ else if (values instanceof Set) { } } } - // `lhs` is now completly calculated, so if we come across it, you don't - // have to go into depth for it anymore, the range of lhs is already the - // transitive closure - done.add(lhs); } return result; }