Skip to content

Commit c3c3773

Browse files
authored
CLJS-3461: don't hard-code destructuring to PAM (#278)
- update `--destructure-map`, `seq-to-map-for-destructuring` for `:lite-mode` - `ObjMap.createAsIfByAssoc`, perf is not critical for `:lite-mode` opt for simplicity for now - add REPL aliases to deps.edn to make it easier to play around with `:lite-mode`
1 parent b69da0e commit c3c3773

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

deps.edn

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
org.clojure/tools.reader {:mvn/version "1.3.6"}
1010
org.clojure/test.check {:mvn/version "1.1.1"}}
1111
:aliases
12-
{:cli.test.run {:extra-paths ["src/test/cljs_cli"]
12+
{:cljs-repl {:extra-paths ["src/test/cljs"]
13+
:main-opts ["-m" "cljs.main" "-re" "node" "-d" ".cljs_repl" "-r"]}
14+
:cljs-lite-repl {:extra-paths ["src/test/cljs"]
15+
:main-opts ["-m" "cljs.main" "-co" "{:lite-mode true}" "-re" "node" "-d" ".cljs_lite_repl" "-r"]}
16+
:cli.test.run {:extra-paths ["src/test/cljs_cli"]
1317
:main-opts ["-i" "src/test/cljs_cli/cljs_cli/test_runner.clj"
1418
"-e" "(cljs-cli.test-runner/-main)"]}
1519
:compiler.test {:extra-paths ["src/test/cljs" "src/test/cljs_build" "src/test/cljs_cp"

src/main/cljs/cljs/core.cljs

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4124,16 +4124,26 @@ reduces them without incurring seq initialization"
41244124

41254125
(set! *unchecked-if* false)
41264126

4127+
(declare ObjMap)
4128+
41274129
;; CLJS-3200: used by destructure macro for maps to reduce amount of repeated code
41284130
;; placed here because it needs apply and hash-map (only declared at this point)
41294131
(defn --destructure-map [gmap]
4130-
(if (implements? ISeq gmap)
4131-
(if (next gmap)
4132-
(.createAsIfByAssoc PersistentArrayMap (to-array gmap))
4133-
(if (seq gmap)
4134-
(first gmap)
4135-
(.-EMPTY PersistentArrayMap)))
4136-
gmap))
4132+
(if ^boolean LITE_MODE
4133+
(if (implements? ISeq gmap)
4134+
(if (next gmap)
4135+
(.createAsIfByAssoc ObjMap (to-array gmap))
4136+
(if (seq gmap)
4137+
(first gmap)
4138+
(.-EMPTY ObjMap)))
4139+
gmap)
4140+
(if (implements? ISeq gmap)
4141+
(if (next gmap)
4142+
(.createAsIfByAssoc PersistentArrayMap (to-array gmap))
4143+
(if (seq gmap)
4144+
(first gmap)
4145+
(.-EMPTY PersistentArrayMap)))
4146+
gmap)))
41374147

41384148
(defn vary-meta
41394149
"Returns an object of the same type and value as obj, with
@@ -7126,7 +7136,7 @@ reduces them without incurring seq initialization"
71267136
(fn [init]
71277137
;; check trailing element
71287138
(let [len (alength init)
7129-
has-trailing? (== 1 (bit-and len 1))]
7139+
has-trailing? (== 1 (bit-and len 1))]
71307140
(if-not (or has-trailing? (pam-dupes? init))
71317141
(PersistentArrayMap. nil (/ len 2) init nil)
71327142
(.createAsIfByAssocComplexPath PersistentArrayMap init has-trailing?)))))
@@ -9039,9 +9049,13 @@ reduces them without incurring seq initialization"
90399049
"Builds a map from a seq as described in
90409050
https://clojure.org/reference/special_forms#keyword-arguments"
90419051
[s]
9042-
(if (next s)
9043-
(.createAsIfByAssoc PersistentArrayMap (to-array s))
9044-
(if (seq s) (first s) (.-EMPTY PersistentArrayMap))))
9052+
(if ^boolean LITE_MODE
9053+
(if (next s)
9054+
(.createAsIfByAssoc ObjMap (to-array s))
9055+
(if (seq s) (first s) (.-EMPTY ObjMap)))
9056+
(if (next s)
9057+
(.createAsIfByAssoc PersistentArrayMap (to-array s))
9058+
(if (seq s) (first s) (.-EMPTY PersistentArrayMap)))))
90459059

90469060
(defn sorted-map
90479061
"keyval => key val
@@ -12731,6 +12745,21 @@ reduces them without incurring seq initialization"
1273112745
(recur (nnext kvs)))
1273212746
(.fromObject ObjMap ks obj)))))
1273312747

12748+
(set! (. ObjMap -createAsIfByAssoc)
12749+
(fn [init]
12750+
;; check trailing element
12751+
(let [len (alength init)
12752+
has-trailing? (== 1 (bit-and len 1))
12753+
init (if has-trailing?
12754+
(pam-grow-seed-array init
12755+
(into {} (aget init (dec len))))
12756+
init)
12757+
len (alength init)]
12758+
(loop [i 0 ret {}]
12759+
(if (< i len)
12760+
(recur (+ i 2) (assoc ret (aget init i) (aget init (inc i))))
12761+
ret)))))
12762+
1273412763
(defn- scan-array-equiv [incr k array]
1273512764
(let [len (alength array)]
1273612765
(loop [i 0]

0 commit comments

Comments
 (0)