Skip to content

Commit 63ff68d

Browse files
puredangerstuarthalloway
authored andcommitted
CLJ-1355 - restore cached hashCode for Symbol and (uncached) hashCode for Keyword
1 parent bb0a51a commit 63ff68d

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/jvm/clojure/lang/Keyword.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class Keyword implements IFn, Comparable, Named, Serializable, IHashEq {
2626
private static ConcurrentHashMap<Symbol, Reference<Keyword>> table = new ConcurrentHashMap();
2727
static final ReferenceQueue rq = new ReferenceQueue();
2828
public final Symbol sym;
29-
final int hash;
29+
final int hasheq;
3030
String _str;
3131

3232
public static Keyword intern(Symbol sym){
@@ -55,7 +55,7 @@ public static Keyword intern(String nsname){
5555

5656
private Keyword(Symbol sym){
5757
this.sym = sym;
58-
hash = sym.hashCode() + 0x9e3779b9;
58+
hasheq = sym.hasheq() + 0x9e3779b9;
5959
}
6060

6161
public static Keyword find(Symbol sym){
@@ -75,11 +75,11 @@ public static Keyword find(String nsname){
7575
}
7676

7777
public final int hashCode(){
78-
return hash;
78+
return sym.hashCode() + 0x9e3779b9;
7979
}
8080

8181
public int hasheq() {
82-
return hash;
82+
return hasheq;
8383
}
8484

8585
public String toString(){

src/jvm/clojure/lang/Symbol.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class Symbol extends AFn implements IObj, Comparable, Named, Serializable
2121
final String ns;
2222
final String name;
2323
final int hash;
24+
final int hasheq;
2425
final IPersistentMap _meta;
2526
String _str;
2627

@@ -67,7 +68,8 @@ static public Symbol intern(String nsname){
6768
private Symbol(String ns_interned, String name_interned){
6869
this.name = name_interned;
6970
this.ns = ns_interned;
70-
this.hash = Util.hashCombine(Util.hasheq(name),Util.hasheq(ns));
71+
this.hash = Util.hashCombine(name.hashCode(), Util.hash(ns));
72+
this.hasheq = Util.hashCombine(Util.hasheq(name),Util.hasheq(ns));
7173
this._meta = null;
7274
}
7375

@@ -88,7 +90,7 @@ public int hashCode(){
8890
}
8991

9092
public int hasheq() {
91-
return hash;
93+
return hasheq;
9294
}
9395

9496
public IObj withMeta(IPersistentMap meta){
@@ -99,7 +101,8 @@ private Symbol(IPersistentMap meta, String ns, String name){
99101
this.name = name;
100102
this.ns = ns;
101103
this._meta = meta;
102-
this.hash = Util.hashCombine(Util.hasheq(name),Util.hasheq(ns));
104+
this.hash = Util.hashCombine(name.hashCode(), Util.hash(ns));
105+
this.hasheq = Util.hashCombine(Util.hasheq(name),Util.hasheq(ns));
103106
}
104107

105108
public int compareTo(Object o){

0 commit comments

Comments
 (0)