Skip to content

Commit e351c98

Browse files
committed
CLJS-1401: Unify runtime & compile time UUID hash calculation
1 parent 771f7cd commit e351c98

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9834,7 +9834,7 @@ Maps become Objects. Arbitrary keys are encoded to by key->js."
98349834
IHash
98359835
(-hash [this]
98369836
(when (nil? __hash)
9837-
(set! __hash (goog.string/hashCode uuid)))
9837+
(set! __hash (hash-string* uuid)))
98389838
__hash)
98399839

98409840
IComparable

src/main/clojure/cljs/compiler.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@
286286
(emits "new Date(" (.getTime date) ")"))
287287

288288
(defmethod emit-constant #?(:clj java.util.UUID :cljs UUID) [^java.util.UUID uuid]
289-
(emits "new cljs.core.UUID(\"" (.toString uuid) "\")"))
289+
(let [uuid-str (.toString uuid)]
290+
(emits "new cljs.core.UUID(\"" uuid-str "\", " (hash uuid-str) ")")))
290291

291292
#?(:clj
292293
(defmacro emit-wrap [env & body]

src/test/cljs/cljs/core_test.cljs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,6 +2922,10 @@
29222922
(is (= 'cljs.core/first?
29232923
(demunge (munge 'cljs.core/first?)))))
29242924

2925+
(deftest test-uuid-compile-and-runtime-hash
2926+
(is (= (hash (.toString #uuid "0d1f9029-40fc-4728-8bdd-9862172d4370"))
2927+
(hash (.toString (UUID. "0d1f9029-40fc-4728-8bdd-9862172d4370" nil))))))
2928+
29252929
(comment
29262930
;; ObjMap
29272931
;; (let [ks (map (partial str "foo") (range 500))

0 commit comments

Comments
 (0)