diff options
author | Shawn O. Pearce <sop@google.com> | 2011-06-17 09:54:49 -0700 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2011-06-17 09:54:49 -0700 |
commit | 21c76f4d2861122087c5f695f441bbd012c36f9d (patch) | |
tree | 7ef22e646a84e5d1d052a8dada0d24d16bb689d0 | |
parent | fe8235a9799c0e6b0d49d1d46431e232ab26324d (diff) | |
download | prolog-cafe-21c76f4d2861122087c5f695f441bbd012c36f9d.tar.gz |
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.
-rw-r--r-- | src/lang/Prolog.java | 5 |
1 files changed, 3 insertions, 2 deletions
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.Reader; import java.io.Writer; import java.util.EnumSet; import java.util.HashMap; +import java.util.IdentityHashMap; /** * Prolog engine. * @@ -78,7 +79,7 @@ public final class Prolog { 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 @@ public final class Prolog { trail = new Trail(); stack = new ChoicePointStack(trail); hashManager = new HashtableOfTerm(); + copyHash = new IdentityHashMap<VariableTerm, VariableTerm>(); } /** @@ -153,7 +155,6 @@ public final class Prolog { 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)) { |