Skip to content

Commit 4f4842a

Browse files
committed
handle sets
1 parent c31e77c commit 4f4842a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12721,3 +12721,15 @@ reduces them without incurring seq initialization"
1272112721
(-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "#{" " " "}" opts coll)))
1272212722

1272312723
(set! (. Set -EMPTY) (Set. nil (. HashMap -EMPTY) empty-unordered-hash))
12724+
12725+
(defn simple-set
12726+
[coll]
12727+
(if (set? coll)
12728+
(with-meta coll nil)
12729+
(let [in (seq coll)]
12730+
(if (nil? in)
12731+
#{}
12732+
(loop [in in out (. Set -EMPTY)]
12733+
(if-not (nil? in)
12734+
(recur (next in) (conj out (first in)))
12735+
out))))))

src/main/clojure/cljs/compiler.cljc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,10 +616,17 @@
616616

617617
:else (emits "cljs.core.PersistentHashSet.createAsIfByAssoc([" (comma-sep items) "])")))
618618

619+
(defn emit-lite-set [items comma-sep distinct-constants?]
620+
(if (empty? items)
621+
(emits "cljs.core.Set.EMPTY")
622+
(emits "cljs.core.simple_set([" (comma-sep items) "])")))
623+
619624
(defmethod emit* :set
620625
[{:keys [items env]}]
621626
(emit-wrap env
622-
(emit-set items comma-sep distinct-constants?)))
627+
(if (ana/lite-mode?)
628+
(emit-lite-set items comma-sep distinct-constants?)
629+
(emit-set items comma-sep distinct-constants?))))
623630

624631
(defn emit-js-object [items emit-js-object-val]
625632
(emits "({")

0 commit comments

Comments
 (0)