From b644d7b7d2936cd886acd57b218840f9fb812d55 Mon Sep 17 00:00:00 2001 From: Oleksandr Yakushev Date: Tue, 8 Oct 2024 20:38:39 +0300 Subject: [PATCH] [jdbc.row] Reduce allocations in fetch-all-columns! --- src/toucan2/jdbc/row.clj | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/toucan2/jdbc/row.clj b/src/toucan2/jdbc/row.clj index 8aea53a..91716b6 100644 --- a/src/toucan2/jdbc/row.clj +++ b/src/toucan2/jdbc/row.clj @@ -331,10 +331,12 @@ (defn- fetch-all-columns! [builder i->thunk transient-row] (log/tracef "Fetching all columns") - (reduce - (partial fetch-column! builder i->thunk) - transient-row - (range 1 (inc (next.jdbc.rs/column-count builder))))) + (let [n (next.jdbc.rs/column-count builder)] + (loop [i 1 + transient-row transient-row] + (if (<= i n) + (recur (inc i) (fetch-column! builder i->thunk transient-row i)) + transient-row)))) (defn- make-realized-row-delay [builder i->thunk ^clojure.lang.Volatile volatile-transient-row] (delay