Permalink
Browse files

CLJ-1355 - restore cached hashCode for Symbol and (uncached) hashCode…

… for Keyword
  • Loading branch information...
1 parent bb0a51a commit 63ff68d3baffe76d5157e07bbfd310fdb5ad3628 @puredanger puredanger committed with stuarthalloway Feb 21, 2014
Showing with 10 additions and 7 deletions.
  1. +4 −4 src/jvm/clojure/lang/Keyword.java
  2. +6 −3 src/jvm/clojure/lang/Symbol.java
@@ -26,7 +26,7 @@
private static ConcurrentHashMap<Symbol, Reference<Keyword>> table = new ConcurrentHashMap();
static final ReferenceQueue rq = new ReferenceQueue();
public final Symbol sym;
-final int hash;
+final int hasheq;
String _str;
public static Keyword intern(Symbol sym){
@@ -55,7 +55,7 @@ public static Keyword intern(String nsname){
private Keyword(Symbol sym){
this.sym = sym;
- hash = sym.hashCode() + 0x9e3779b9;
+ hasheq = sym.hasheq() + 0x9e3779b9;
}
public static Keyword find(Symbol sym){
@@ -75,11 +75,11 @@ public static Keyword find(String nsname){
}
public final int hashCode(){
- return hash;
+ return sym.hashCode() + 0x9e3779b9;
}
public int hasheq() {
- return hash;
+ return hasheq;
}
public String toString(){
@@ -21,6 +21,7 @@
final String ns;
final String name;
final int hash;
+final int hasheq;
final IPersistentMap _meta;
String _str;
@@ -67,7 +68,8 @@ static public Symbol intern(String nsname){
private Symbol(String ns_interned, String name_interned){
this.name = name_interned;
this.ns = ns_interned;
- this.hash = Util.hashCombine(Util.hasheq(name),Util.hasheq(ns));
+ this.hash = Util.hashCombine(name.hashCode(), Util.hash(ns));
+ this.hasheq = Util.hashCombine(Util.hasheq(name),Util.hasheq(ns));
this._meta = null;
}
@@ -88,7 +90,7 @@ public int hashCode(){
}
public int hasheq() {
- return hash;
+ return hasheq;
}
public IObj withMeta(IPersistentMap meta){
@@ -99,7 +101,8 @@ private Symbol(IPersistentMap meta, String ns, String name){
this.name = name;
this.ns = ns;
this._meta = meta;
- this.hash = Util.hashCombine(Util.hasheq(name),Util.hasheq(ns));
+ this.hash = Util.hashCombine(name.hashCode(), Util.hash(ns));
+ this.hasheq = Util.hashCombine(Util.hasheq(name),Util.hasheq(ns));
}
public int compareTo(Object o){

0 comments on commit 63ff68d

Please sign in to comment.