Browse files

CLJS-492: avoid producing unnecessary calls to next in emit-apply-to

Includes two new entries in benchmark_runner.cljs.
  • Loading branch information...
1 parent 3ca249a commit 1a094e41ba482de1bc2e363874cdb29414bdac46 @michalmarczyk michalmarczyk committed with swannodette Apr 1, 2013
Showing with 8 additions and 13 deletions.
  1. +2 −0 benchmark/cljs/benchmark_runner.cljs
  2. +6 −13 src/clj/cljs/compiler.clj
View
2 benchmark/cljs/benchmark_runner.cljs
@@ -92,6 +92,8 @@
(simple-benchmark [xs (array-seq (array 1 2 3 4 5))] (apply list xs) 1000000)
(simple-benchmark [xs (list 1 2 3 4 5)] (apply list xs) 1000000)
(simple-benchmark [xs [1 2 3 4 5]] (apply list xs) 1000000)
+(simple-benchmark [f (fn [a b & more])] (apply f (range 32)) 1000000)
+(simple-benchmark [f (fn [a b c d e f g h i j & more])] (apply f (range 32)) 1000000)
(println)
(println ";; update-in")
View
19 src/clj/cljs/compiler.clj
@@ -382,24 +382,17 @@
delegate-name (str (munge name) "__delegate")
params (map munge params)]
(emitln "(function (" arglist "){")
- (doseq [[i param] (map-indexed vector (butlast params))]
+ (doseq [[i param] (map-indexed vector (drop-last 2 params))]
(emits "var " param " = cljs.core.first(")
- (dotimes [_ i] (emits "cljs.core.next("))
- (emits arglist ")")
- (dotimes [_ i] (emits ")"))
- (emitln ";"))
+ (emitln arglist ");")
+ (emitln arglist " = cljs.core.next(" arglist ");"))
(if (< 1 (count params))
(do
- (emits "var " (last params) " = cljs.core.rest(")
- (dotimes [_ (- (count params) 2)] (emits "cljs.core.next("))
- (emits arglist)
- (dotimes [_ (- (count params) 2)] (emits ")"))
- (emitln ");")
+ (emitln "var " (last (butlast params)) " = cljs.core.first(" arglist ");")
+ (emitln "var " (last params) " = cljs.core.rest(" arglist ");")
(emitln "return " delegate-name "(" (string/join ", " params) ");"))
(do
- (emits "var " (last params) " = ")
- (emits "cljs.core.seq(" arglist ");")
- (emitln ";")
+ (emitln "var " (last params) " = cljs.core.seq(" arglist ");")
(emitln "return " delegate-name "(" (string/join ", " params) ");")))
(emits "})")))

0 comments on commit 1a094e4

Please sign in to comment.