merge in optimizations to END

This commit is contained in:
Nathan Marz 2016-06-07 16:11:21 -04:00
commit 0f475ddba3
5 changed files with 50 additions and 7 deletions

View file

@ -3,6 +3,7 @@
* Huge performance improvement for ALL transform on maps and vectors * Huge performance improvement for ALL transform on maps and vectors
* Significant performance improvements for FIRST/LAST for vectors * Significant performance improvements for FIRST/LAST for vectors
* Huge performance improvements for `if-path`, `cond-path`, `selected?`, and `not-selected?`, especially for condition path containing only static functions * Huge performance improvements for `if-path`, `cond-path`, `selected?`, and `not-selected?`, especially for condition path containing only static functions
* Huge performance improvement for `END` on vectors
* Added specialized MAP-VALS navigator that is twice as fast as using [ALL LAST] * Added specialized MAP-VALS navigator that is twice as fast as using [ALL LAST]
* Eliminated compiler warnings for ClojureScript version * Eliminated compiler warnings for ClojureScript version
* Dropped support for Clojurescript below v1.7.10 * Dropped support for Clojurescript below v1.7.10

View file

@ -14,7 +14,8 @@
:codox {:source-paths ["target/classes" "src/clj"] :codox {:source-paths ["target/classes" "src/clj"]
:namespaces [com.rpl.specter :namespaces [com.rpl.specter
com.rpl.specter.macros com.rpl.specter.macros
com.rpl.specter.zipper] com.rpl.specter.zipper
com.rpl.specter.protocols]
:source-uri :source-uri
{#"target/classes" "https://github.com/nathanmarz/specter/tree/{version}/src/clj/{classpath}x#L{line}" {#"target/classes" "https://github.com/nathanmarz/specter/tree/{version}/src/clj/{classpath}x#L{line}"
#".*" "https://github.com/nathanmarz/specter/tree/{version}/src/clj/{classpath}#L{line}" #".*" "https://github.com/nathanmarz/specter/tree/{version}/src/clj/{classpath}#L{line}"

View file

@ -51,7 +51,6 @@
(println "\n********************************\n") (println "\n********************************\n")
))) )))
(let [data {:a {:b {:c 1}}} (let [data {:a {:b {:c 1}}}
p (comp-paths :a :b :c)] p (comp-paths :a :b :c)]
(run-benchmark "get value in nested map" 10000000 (run-benchmark "get value in nested map" 10000000
@ -104,6 +103,12 @@
(->> data (mapv :a) (filter even?) doall) (->> data (mapv :a) (filter even?) doall)
)) ))
(let [v (vec (range 1000))]
(run-benchmark "END on large vector"
5000000
(setval END [1] v)
(reduce conj v [1])
(conj v 1)))
(defn- update-pair [[k v]] (defn- update-pair [[k v]]
[k (inc v)]) [k (inc v)])

View file

@ -252,15 +252,27 @@
(reverse (i/matching-ranges structure pred)) (reverse (i/matching-ranges structure pred))
))) )))
(def (defnav
^{:doc "Navigate to the empty subsequence before the first element of the collection."} ^{:doc "Navigate to the empty subsequence before the first element of the collection."}
BEGINNING BEGINNING
(srange 0 0)) []
(select* [this structure next-fn]
(next-fn []))
(transform* [this structure next-fn]
(let [to-prepend (next-fn [])]
(i/prepend-all structure to-prepend)
)))
(def (defnav
^{:doc "Navigate to the empty subsequence after the last element of the collection."} ^{:doc "Navigate to the empty subsequence after the last element of the collection."}
END END
(srange-dynamic count count)) []
(select* [this structure next-fn]
(next-fn []))
(transform* [this structure next-fn]
(let [to-append (next-fn [])]
(i/append-all structure to-append)
)))
(defnav (defnav
^{:doc "Navigates to the specified subset (by taking an intersection). ^{:doc "Navigates to the specified subset (by taking an intersection).

View file

@ -474,6 +474,30 @@
(defn- append [coll elem] (defn- append [coll elem]
(-> coll vec (conj elem))) (-> coll vec (conj elem)))
(defprotocol AddExtremes
(append-all [structure elements])
(prepend-all [structure elements]))
(extend-protocol AddExtremes
#+clj clojure.lang.PersistentVector #+cljs cljs.core/PersistentVector
(append-all [structure elements]
(reduce conj structure elements))
(prepend-all [structure elements]
(let [ret (transient [])]
(as-> ret <>
(reduce conj! <> elements)
(reduce conj! <> structure)
(persistent! <>)
)))
#+clj Object #+cljs default
(append-all [structure elements]
(concat structure elements))
(prepend-all [structure elements]
(concat elements structure))
)
(defprotocol UpdateExtremes (defprotocol UpdateExtremes
(update-first [s afn]) (update-first [s afn])
(update-last [s afn])) (update-last [s afn]))