optimization for using comp-paths on already compiled path

This commit is contained in:
Nathan Marz 2016-05-24 17:29:34 -04:00
parent b8bcfd6054
commit 73e460df80

View file

@ -22,9 +22,6 @@
(println (pr-str e)) (println (pr-str e))
e) e)
(defprotocol PathComposer
(comp-paths* [paths]))
(defn- smart-str* [o] (defn- smart-str* [o]
(if (coll? o) (if (coll? o)
(pr-str o) (pr-str o)
@ -134,6 +131,13 @@
params params
idx)) idx))
(defprotocol PathComposer
(do-comp-paths [paths]))
(defn comp-paths* [p]
(if (compiled-path? p) p (do-comp-paths p))
)
(defn- seq-contains? [aseq val] (defn- seq-contains? [aseq val]
(->> aseq (->> aseq
(filter (partial = val)) (filter (partial = val))
@ -238,7 +242,7 @@
#+clj java.util.List #+cljs cljs.core/PersistentVector #+clj java.util.List #+cljs cljs.core/PersistentVector
(coerce-path [this] (coerce-path [this]
(comp-paths* this)) (do-comp-paths this))
#+cljs cljs.core/IndexedSeq #+cljs cljs.core/IndexedSeq
#+cljs (coerce-path [this] #+cljs (coerce-path [this]
@ -331,13 +335,13 @@
(extend-protocol PathComposer (extend-protocol PathComposer
nil nil
(comp-paths* [sp] (do-comp-paths [sp]
(coerce-path sp)) (coerce-path sp))
#+clj Object #+cljs default #+clj Object #+cljs default
(comp-paths* [sp] (do-comp-paths [sp]
(coerce-path sp)) (coerce-path sp))
#+clj java.util.List #+cljs cljs.core/PersistentVector #+clj java.util.List #+cljs cljs.core/PersistentVector
(comp-paths* [structure-paths] (do-comp-paths [structure-paths]
(if (empty? structure-paths) (if (empty? structure-paths)
(coerce-path nil) (coerce-path nil)
(let [coerced (->> structure-paths (let [coerced (->> structure-paths