Skip to content

Commit 9b044f7

Browse files
[perf] Optimize m.instrument/clj-collect!
1 parent a74e3b4 commit 9b044f7

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/malli/instrument.clj

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,18 @@
5252
(defn clj-collect!
5353
([] (clj-collect! {:ns *ns*}))
5454
([{:keys [ns]}]
55-
(not-empty (reduce (fn [acc v] (let [v (-collect! v)] (cond-> acc v (conj v)))) #{} (vals (mapcat ns-publics (-sequential ns)))))))
55+
(not-empty
56+
(reduce (fn [acc nspace] ns-publics
57+
(let [nspace (the-ns nspace)]
58+
(reduce-kv (fn [acc _ ^clojure.lang.Var v]
59+
(if-let [v (and (instance? clojure.lang.Var v)
60+
(= nspace (.ns v))
61+
(not (:private (meta v)))
62+
(-collect! v))]
63+
(conj acc v)
64+
acc))
65+
acc (ns-map nspace))))
66+
#{} (-sequential ns)))))
5667

5768
;;
5869
;; CLJS macro for collecting function schemas

0 commit comments

Comments
 (0)