optimized protocol invocations for cljs
This commit is contained in:
parent
a76f124579
commit
80e1e3dd30
2 changed files with 21 additions and 8 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
(ns com.rpl.specter.impl
|
(ns com.rpl.specter.impl
|
||||||
|
#?(:cljs (:require-macros [com.rpl.specter.prot-opt-invoke
|
||||||
|
:refer [mk-optimized-invocation]]))
|
||||||
(:use [com.rpl.specter.protocols :only
|
(:use [com.rpl.specter.protocols :only
|
||||||
[comp-paths*
|
[comp-paths*
|
||||||
select* transform* collect-val select-full* transform-full*]])
|
select* transform* collect-val select-full* transform-full*]])
|
||||||
|
|
@ -100,20 +102,21 @@
|
||||||
(find-protocol-impl! p/StructureValsPath this))
|
(find-protocol-impl! p/StructureValsPath this))
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
#?(:cljs
|
#?(:cljs
|
||||||
(do
|
(do
|
||||||
(defn structure-path-impl [_]
|
(defn structure-path-impl [obj]
|
||||||
{:select* select*
|
{:select* (mk-optimized-invocation p/StructurePath obj select* 2)
|
||||||
:transform* transform*
|
:transform* (mk-optimized-invocation p/StructurePath obj transform* 2)
|
||||||
})
|
})
|
||||||
|
|
||||||
(defn collector-impl [_]
|
(defn collector-impl [obj]
|
||||||
{:collect-val collect-val
|
{:collect-val (mk-optimized-invocation p/Collector obj collect-val 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
(defn structure-vals-path-impl [_]
|
(defn structure-vals-path-impl [obj]
|
||||||
{:select-full* select-full*
|
{:select-full* (mk-optimized-invocation p/StructureValsPath obj select-full* 3)
|
||||||
:transform-full* transform-full*
|
:transform-full* (mk-optimized-invocation p/StructureValsPath obj transform-full* 3)
|
||||||
})
|
})
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
|
||||||
10
src/com/rpl/specter/prot_opt_invoke.clj
Normal file
10
src/com/rpl/specter/prot_opt_invoke.clj
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
(ns com.rpl.specter.prot-opt-invoke)
|
||||||
|
|
||||||
|
(defmacro mk-optimized-invocation [protocol obj method num-args]
|
||||||
|
(let [args (take num-args (repeatedly gensym))]
|
||||||
|
`(if (~'implements? ~protocol ~obj)
|
||||||
|
(fn [^not-native o# ~@args]
|
||||||
|
(~method o# ~@args)
|
||||||
|
)
|
||||||
|
~method
|
||||||
|
)))
|
||||||
Loading…
Reference in a new issue