expand optimized if-path to encompass any sequence of static functions

This commit is contained in:
Nathan Marz 2016-06-04 21:22:57 -04:00
parent 18e736e5d8
commit f82ab31b36
3 changed files with 17 additions and 6 deletions

View file

@ -2,7 +2,7 @@
* More efficient inline caching for Clojure version, now inline caching is always within 5% of manually precompiled code * More efficient inline caching for Clojure version, now inline caching is always within 5% of manually precompiled code
* 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` and `cond-path`, especially for condition path containing a single static function * Huge performance improvements for `if-path` and `cond-path`, especially for condition path containing only static functions
* 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
* Added :notpath metadata to signify pathedfn arguments that should be treated as regular arguments during inline factoring. If one of these arguments is not a static var reference or a non-collection value, the path will not factor. * Added :notpath metadata to signify pathedfn arguments that should be treated as regular arguments during inline factoring. If one of these arguments is not a static var reference or a non-collection value, the path will not factor.

View file

@ -762,11 +762,14 @@
path path
(and (coll? path) (and (coll? path)
(= 1 (count path)) (every? fn? path))
(fn? (first path))) (reduce
(first path) (fn [combined afn]
(fn [structure]
(and (combined structure) (afn structure))
)) ))
path
)))
(defn if-select [structure next-fn then-tester late-then late-else] (defn if-select [structure next-fn then-tester late-then late-else]
(let [apath (if (then-tester structure) (let [apath (if (then-tester structure)

View file

@ -400,6 +400,14 @@
(select k m)) (select k m))
)))) ))))
(deftest optimized-if-path-test
(is (= [-4 -2] (select [s/ALL (s/if-path [even? neg?] s/STAY)]
[1 2 -3 -4 0 -2])))
(is (= [1 2 -3 4 0 2] (transform [s/ALL (s/if-path [even? neg?] s/STAY)]
-
[1 2 -3 -4 0 -2])))
)
(defspec multi-path-test (defspec multi-path-test
(for-all+ (for-all+
[k1 (limit-size 3 gen/keyword) [k1 (limit-size 3 gen/keyword)