Skip to content

Commit

Permalink
CLJ-1355 - restore cached hashCode for Symbol and (uncached) hashCode…
Browse files Browse the repository at this point in the history
… for Keyword
  • Loading branch information
puredanger authored and stuarthalloway committed Feb 27, 2014
1 parent bb0a51a commit 63ff68d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/jvm/clojure/lang/Keyword.java
Expand Up @@ -26,7 +26,7 @@ public class Keyword implements IFn, Comparable, Named, Serializable, IHashEq {
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){
Expand Down Expand Up @@ -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){
Expand All @@ -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(){
Expand Down
9 changes: 6 additions & 3 deletions src/jvm/clojure/lang/Symbol.java
Expand Up @@ -21,6 +21,7 @@ public class Symbol extends AFn implements IObj, Comparable, Named, Serializable
final String ns;
final String name;
final int hash;
final int hasheq;
final IPersistentMap _meta;
String _str;

Expand Down Expand Up @@ -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;
}

Expand All @@ -88,7 +90,7 @@ public int hashCode(){
}

public int hasheq() {
return hash;
return hasheq;
}

public IObj withMeta(IPersistentMap meta){
Expand All @@ -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){
Expand Down

0 comments on commit 63ff68d

Please sign in to comment.