Skip to content

Commit 8599507

Browse files
nurkiewiczstuarthalloway
authored andcommitted
CLJ-1408 - make cached string value of Keyword and Symbol transient
Signed-off-by: Stuart Halloway <[email protected]>
1 parent 2b8e207 commit 8599507

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/jvm/clojure/lang/Keyword.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class Keyword implements IFn, Comparable, Named, Serializable, IHashEq {
2727
static final ReferenceQueue rq = new ReferenceQueue();
2828
public final Symbol sym;
2929
final int hasheq;
30-
String _str;
30+
transient String _str;
3131

3232
public static Keyword intern(Symbol sym){
3333
Keyword k = null;

src/jvm/clojure/lang/Symbol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Symbol extends AFn implements IObj, Comparable, Named, Serializable
2121
final String name;
2222
private int _hasheq;
2323
final IPersistentMap _meta;
24-
String _str;
24+
transient String _str;
2525

2626
public String toString(){
2727
if(_str == null){

test/clojure/test_clojure/serialization.clj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@
122122
::namespaced-keyword
123123
'symbol))
124124

125+
(deftest tostringed-bytes
126+
(let [rt #(-> % serialize seq)
127+
s1 (rt 'sym123)
128+
k1 (rt :kw123)
129+
_ (.toString 'sym123)
130+
_ (.toString :kw123)
131+
s2 (rt 'sym123)
132+
k2 (rt :kw123)]
133+
(is (= s1 s2))
134+
(is (= k1 k2))))
135+
125136
(deftest interned-serializations
126137
(are [v] (identical? v (-> v serialize deserialize))
127138
clojure.lang.RT/DEFAULT_COMPARATOR

0 commit comments

Comments
 (0)