From cc7de6c1343f5133333ddc996f4210325a70c6b9 Mon Sep 17 00:00:00 2001 From: Oleksandr Yakushev Date: Mon, 17 Mar 2025 01:10:29 +0200 Subject: [PATCH] [dispatcher] Use more efficient iteration in matching-primary-pairs --- src/methodical/impl/dispatcher/standard.clj | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/methodical/impl/dispatcher/standard.clj b/src/methodical/impl/dispatcher/standard.clj index 036aa98..6ff5890 100644 --- a/src/methodical/impl/dispatcher/standard.clj +++ b/src/methodical/impl/dispatcher/standard.clj @@ -19,9 +19,10 @@ method (if any); pairs are sorted in order from most-specific to least-specific." [{:keys [hierarchy prefs method-map dispatch-value]}] {:pre [(map? method-map)]} - (let [matches (for [[a-dispatch-val method] method-map - :when (isa? hierarchy dispatch-value a-dispatch-val)] - [a-dispatch-val method])] + (let [matches (reduce-kv (fn [acc a-dispatch-val method] + (cond-> acc + (isa? hierarchy dispatch-value a-dispatch-val) (conj [a-dispatch-val method]))) + [] method-map)] (when (seq matches) (sort-by first (dispatcher.common/domination-comparator hierarchy prefs dispatch-value) matches))))