From f7d0383919e8fe2cabf87cf89ee1d68a87a5c100 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 15 Mar 2021 08:38:01 +0100 Subject: [PATCH] :zap: Improve performance of enumerate data helper. --- common/app/common/data.cljc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/common/app/common/data.cljc b/common/app/common/data.cljc index bc3d14dba..26722cf75 100644 --- a/common/app/common/data.cljc +++ b/common/app/common/data.cljc @@ -42,7 +42,6 @@ ([a b & rest] (reduce deep-merge a (cons b rest)))) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Data Structures Manipulation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -70,14 +69,14 @@ (defn enumerate ([items] (enumerate items 0)) ([items start] - (loop [idx start + (loop [idx start items items - res []] + res (transient [])] (if (empty? items) - res + (persistent! res) (recur (inc idx) (rest items) - (conj res [idx (first items)])))))) + (conj! res [idx (first items)])))))) (defn seek ([pred coll]