optimize lookup of structurepath implementation for regular functions (about a 3x speedup in non-compiled execution when functions are involved
This commit is contained in:
parent
7f69a99861
commit
085dc1d333
1 changed files with 13 additions and 4 deletions
|
|
@ -83,8 +83,14 @@
|
||||||
)]
|
)]
|
||||||
(->TransformFunctions StructureValsPathExecutor afn afn)))
|
(->TransformFunctions StructureValsPathExecutor afn afn)))
|
||||||
|
|
||||||
|
|
||||||
|
(defn structure-path-impl [this]
|
||||||
|
(if (fn? this)
|
||||||
|
(-> StructurePath :impls (get clojure.lang.AFn))
|
||||||
|
(find-protocol-impl! StructurePath this)))
|
||||||
|
|
||||||
(defn coerce-structure-path [this]
|
(defn coerce-structure-path [this]
|
||||||
(let [pimpl (find-protocol-impl! StructurePath this)
|
(let [pimpl (structure-path-impl this)
|
||||||
selector (:select* pimpl)
|
selector (:select* pimpl)
|
||||||
updater (:update* pimpl)]
|
updater (:update* pimpl)]
|
||||||
(->TransformFunctions
|
(->TransformFunctions
|
||||||
|
|
@ -96,7 +102,7 @@
|
||||||
)))
|
)))
|
||||||
|
|
||||||
(defn coerce-structure-path-direct [this]
|
(defn coerce-structure-path-direct [this]
|
||||||
(let [pimpl (find-protocol-impl! StructurePath this)
|
(let [pimpl (structure-path-impl this)
|
||||||
selector (:select* pimpl)
|
selector (:select* pimpl)
|
||||||
updater (:update* pimpl)]
|
updater (:update* pimpl)]
|
||||||
(->TransformFunctions
|
(->TransformFunctions
|
||||||
|
|
@ -110,6 +116,9 @@
|
||||||
(defn obj-extends? [prot obj]
|
(defn obj-extends? [prot obj]
|
||||||
(->> obj (find-protocol-impl prot) nil? not))
|
(->> obj (find-protocol-impl prot) nil? not))
|
||||||
|
|
||||||
|
(defn structure-path? [obj]
|
||||||
|
(or (fn? obj) (obj-extends? StructurePath obj)))
|
||||||
|
|
||||||
(extend-protocol CoerceTransformFunctions
|
(extend-protocol CoerceTransformFunctions
|
||||||
|
|
||||||
TransformFunctions
|
TransformFunctions
|
||||||
|
|
@ -122,7 +131,7 @@
|
||||||
|
|
||||||
Object
|
Object
|
||||||
(coerce-path [this]
|
(coerce-path [this]
|
||||||
(cond (obj-extends? StructurePath this) (coerce-structure-path this)
|
(cond (structure-path? this) (coerce-structure-path this)
|
||||||
(obj-extends? Collector this) (coerce-collector this)
|
(obj-extends? Collector this) (coerce-collector this)
|
||||||
(obj-extends? StructureValsPath this) (coerce-structure-vals-path this)
|
(obj-extends? StructureValsPath this) (coerce-structure-vals-path this)
|
||||||
:else (throw-illegal (no-prot-error-str this))
|
:else (throw-illegal (no-prot-error-str this))
|
||||||
|
|
@ -192,7 +201,7 @@
|
||||||
))))
|
))))
|
||||||
|
|
||||||
(defn coerce-structure-vals-direct [this]
|
(defn coerce-structure-vals-direct [this]
|
||||||
(cond (obj-extends? StructurePath this) (coerce-structure-path-direct this)
|
(cond (structure-path? this) (coerce-structure-path-direct this)
|
||||||
(obj-extends? Collector this) (coerce-collector this)
|
(obj-extends? Collector this) (coerce-collector this)
|
||||||
(obj-extends? StructureValsPath this) (coerce-structure-vals-path this)
|
(obj-extends? StructureValsPath this) (coerce-structure-vals-path this)
|
||||||
(instance? TransformFunctions this) this
|
(instance? TransformFunctions this) this
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue