Skip to content

Commit

Permalink
CLJS-3200: reduce code generated by destructure macro for maps
Browse files Browse the repository at this point in the history
  • Loading branch information
thheller authored and swannodette committed Aug 5, 2020
1 parent bdbd6c5 commit 4c78017
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/cljs/cljs/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3986,6 +3986,11 @@ reduces them without incurring seq initialization"

(set! *unchecked-if* false)

;; CLJS-3200: used by destructure macro for maps to reduce amount of repeated code
;; placed here because it needs apply and hash-map (only declared at this point)
(defn --destructure-map [x]
(if (implements? ISeq x) (apply cljs.core/hash-map x) x))

(defn vary-meta
"Returns an object of the same type and value as obj, with
(apply f (meta obj) args) as its metadata."
Expand Down
2 changes: 1 addition & 1 deletion src/main/clojure/cljs/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@
(core/let [gmap (gensym "map__")
defaults (:or b)]
(core/loop [ret (core/-> bvec (conj gmap) (conj v)
(conj gmap) (conj `(if (implements? ISeq ~gmap) (apply cljs.core/hash-map ~gmap) ~gmap))
(conj gmap) (conj `(--destructure-map ~gmap))
((core/fn [ret]
(if (:as b)
(conj ret (:as b) gmap)
Expand Down

0 comments on commit 4c78017

Please sign in to comment.