From b46995281acacd6eecd9c232ab2318ad34d1ac9b Mon Sep 17 00:00:00 2001 From: David Nolen Date: Mon, 28 May 2012 14:06:13 -0400 Subject: [PATCH] * benchmark/cljs/benchmark_runner.cljs: CLJS-244: Brian Taylor's list create optimization --- benchmark/cljs/benchmark_runner.cljs | 3 ++- src/cljs/cljs/core.cljs | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/benchmark/cljs/benchmark_runner.cljs b/benchmark/cljs/benchmark_runner.cljs index da1a4e5df2..d0d48d6548 100644 --- a/benchmark/cljs/benchmark_runner.cljs +++ b/benchmark/cljs/benchmark_runner.cljs @@ -19,7 +19,8 @@ (simple-benchmark [coll (list 1 2 3)] (-first coll) 1000000) (simple-benchmark [coll (list 1 2 3)] (rest coll) 1000000) (simple-benchmark [coll (list 1 2 3)] (-rest coll) 1000000) -(simple-benchmark [coll (list 1 2 3)] (next coll) 1000000) +(simple-benchmark [] (list) 1000000) +(simple-benchmark [] (list 1 2 3) 1000000) (println) (println ";;; vector ops") diff --git a/src/cljs/cljs/core.cljs b/src/cljs/cljs/core.cljs index 8484bf7337..c4f8e28e8a 100644 --- a/src/cljs/cljs/core.cljs +++ b/src/cljs/cljs/core.cljs @@ -1547,8 +1547,14 @@ reduces them without incurring seq initialization" (rseq coll) (reduce conj () coll))) -(defn list [& items] - (reduce conj () (reverse items))) +(defn list + ([] ()) + ([x] (conj () x)) + ([x y] (conj (list y) x)) + ([x y z] (conj (list y z) x)) + ([x y z & items] + (conj (conj (conj (reduce conj () (reverse items)) + z) y) x))) (deftype Cons [meta first rest ^:mutable __hash] IList