Make Prolog.copyHash an IdentityHashMap
The map is used only for VariableTerms that have not yet
been resolved to a value. In this case the only equality
that makes sense is identity equality. The identity map
is faster as it always avoids the virtual hashCode()
and equals() methods on the keys.
diff --git a/src/lang/Prolog.java b/src/lang/Prolog.java
index a890026..d744667 100644
--- a/src/lang/Prolog.java
+++ b/src/lang/Prolog.java
@@ -10,6 +10,7 @@
import java.io.Writer;
import java.util.EnumSet;
import java.util.HashMap;
+import java.util.IdentityHashMap;
/**
* Prolog engine.
*
@@ -78,7 +79,7 @@
protected long previousRuntime;
/** Hashtable for creating a copy of term. */
- protected HashMap<VariableTerm,VariableTerm> copyHash;
+ protected final IdentityHashMap<VariableTerm,VariableTerm> copyHash;
/** The size of the pushback buffer used for creating input streams. */
public static final int PUSHBACK_SIZE = 3;
@@ -134,6 +135,7 @@
trail = new Trail();
stack = new ChoicePointStack(trail);
hashManager = new HashtableOfTerm();
+ copyHash = new IdentityHashMap<VariableTerm, VariableTerm>();
}
/**
@@ -153,7 +155,6 @@
if (pcl == null) pcl = new PrologClassLoader();
if (internalDB == null) internalDB = new InternalDatabase();
- copyHash = new HashMap<VariableTerm, VariableTerm>();
streamManager = new HashtableOfTerm();
if (features.contains(Feature.IO)) {