From b773a7f4ed4942148ad1045d4290bb9b10a39d7c Mon Sep 17 00:00:00 2001 From: Ben Sless Date: Sat, 21 Aug 2021 11:59:53 +0300 Subject: [PATCH 1/4] Faster registry constructor --- src/malli/registry.cljc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/malli/registry.cljc b/src/malli/registry.cljc index 8f90f3e77..f035fd3c5 100644 --- a/src/malli/registry.cljc +++ b/src/malli/registry.cljc @@ -14,9 +14,19 @@ (-schema [_ type] (get schemas type)) (-schemas [_] schemas))) -(defn registry [?registry] - (cond (satisfies? Registry ?registry) ?registry - (map? ?registry) (simple-registry ?registry))) +(defn registry + [?registry] + #?(:clj + (when ?registry + (if (instance? malli.registry.Registry ?registry) + ?registry + (if (map? ?registry) + (simple-registry ?registry) + (when (satisfies? Registry ?registry) + ?registry)))) + :cljs + (cond (satisfies? Registry ?registry) ?registry + (map? ?registry) (simple-registry ?registry)))) ;; ;; custom From 7f5e860113ef369d10e753b473810759b7b5e705 Mon Sep 17 00:00:00 2001 From: Ben Sless Date: Sat, 21 Aug 2021 12:00:26 +0300 Subject: [PATCH 2/4] Faster simple-registry lookup --- src/malli/registry.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/malli/registry.cljc b/src/malli/registry.cljc index f035fd3c5..9fb6cf74a 100644 --- a/src/malli/registry.cljc +++ b/src/malli/registry.cljc @@ -11,7 +11,7 @@ (defn simple-registry [schemas] (reify Registry - (-schema [_ type] (get schemas type)) + (-schema [_ type] (schemas type)) (-schemas [_] schemas))) (defn registry From 0417e16a44badd5d1ce2b5c96a372ee2a3f877e4 Mon Sep 17 00:00:00 2001 From: Ben Sless Date: Sat, 21 Aug 2021 12:00:48 +0300 Subject: [PATCH 3/4] Faster -registry --- src/malli/core.cljc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/malli/core.cljc b/src/malli/core.cljc index 05adc3bdd..6e3c1ae34 100644 --- a/src/malli/core.cljc +++ b/src/malli/core.cljc @@ -251,8 +251,12 @@ (assoc @v schema)))) (defn -registry + {:arglists '([] [{:keys [registry]}])} ([] default-registry) - ([{:keys [registry]}] (or (mr/registry registry) default-registry))) + ([opts] + (or (when opts + (mr/registry (opts :registry))) + default-registry))) (defn- -lookup [?schema options] (let [registry (-registry options)] From 0f22aa45110c56c18792ee85e7bd4cf5bd750370 Mon Sep 17 00:00:00 2001 From: Ben Sless Date: Sat, 21 Aug 2021 12:32:35 +0300 Subject: [PATCH 4/4] Fix unparse in triplet test --- test/malli/core_test.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/malli/core_test.cljc b/test/malli/core_test.cljc index e17f7e04a..75ae6f315 100644 --- a/test/malli/core_test.cljc +++ b/test/malli/core_test.cljc @@ -1435,7 +1435,7 @@ (and (= (m/validate s v) (nil? es)) (results= (m/explain s v) (and es {:schema s, :value v, :errors es})) (= (m/parse s v) (if (nil? es) (if (= typ :cat) v v*) ::m/invalid)) - (or (some? es) (= (m/unparse s (if (= typ :cat) v v*) s) v)))) + (or (some? es) (= (m/unparse s (if (= typ :cat) v v*)) v)))) 0 nil [{:path [], :in [], :schema s, :value 0, :type ::m/invalid-type}] "foo" nil [{:path [], :in [], :schema s, :value "foo", :type ::m/invalid-type}]