mirror of https://github.com/status-im/reagent.git
Use unchecked-aget/aset in with-let macro
This commit is contained in:
parent
b8f80f56f9
commit
f2622f1544
|
@ -14,6 +14,25 @@
|
||||||
(deref co#)
|
(deref co#)
|
||||||
co#))
|
co#))
|
||||||
|
|
||||||
|
; taken from cljs.core
|
||||||
|
; https://github.com/binaryage/cljs-oops/issues/14
|
||||||
|
(defmacro unchecked-aget
|
||||||
|
([array idx]
|
||||||
|
(list 'js* "(~{}[~{}])" array idx))
|
||||||
|
([array idx & idxs]
|
||||||
|
(let [astr (apply str (repeat (count idxs) "[~{}]"))]
|
||||||
|
`(~'js* ~(str "(~{}[~{}]" astr ")") ~array ~idx ~@idxs))))
|
||||||
|
|
||||||
|
; taken from cljs.core
|
||||||
|
; https://github.com/binaryage/cljs-oops/issues/14
|
||||||
|
(defmacro unchecked-aset
|
||||||
|
([array idx val]
|
||||||
|
(list 'js* "(~{}[~{}] = ~{})" array idx val))
|
||||||
|
([array idx idx2 & idxv]
|
||||||
|
(let [n (dec (count idxv))
|
||||||
|
astr (apply str (repeat n "[~{}]"))]
|
||||||
|
`(~'js* ~(str "(~{}[~{}][~{}]" astr " = ~{})") ~array ~idx ~idx2 ~@idxv))))
|
||||||
|
|
||||||
(defmacro with-let [bindings & body]
|
(defmacro with-let [bindings & body]
|
||||||
(assert (vector? bindings)
|
(assert (vector? bindings)
|
||||||
(str "with-let bindings must be a vector, not "
|
(str "with-let bindings must be a vector, not "
|
||||||
|
@ -27,8 +46,8 @@
|
||||||
x
|
x
|
||||||
(let [j (quot i 2)]
|
(let [j (quot i 2)]
|
||||||
`(if ~init
|
`(if ~init
|
||||||
(aset ~v ~j ~x)
|
(unchecked-aset ~v ~j ~x)
|
||||||
(aget ~v ~j)))))
|
(unchecked-aget ~v ~j)))))
|
||||||
bindings))
|
bindings))
|
||||||
[forms destroy] (let [fin (last body)]
|
[forms destroy] (let [fin (last body)]
|
||||||
(if (and (list? fin)
|
(if (and (list? fin)
|
||||||
|
|
Loading…
Reference in New Issue