From da9c94e52067f4cdd0e471fe739d840ba214243b Mon Sep 17 00:00:00 2001 From: Tommi Reiman Date: Mon, 2 Oct 2017 08:07:15 +0300 Subject: [PATCH] Fast path matching with .equals --- src/reitit/impl.cljc | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/reitit/impl.cljc b/src/reitit/impl.cljc index 9d81dfee..9b4c6d1e 100644 --- a/src/reitit/impl.cljc +++ b/src/reitit/impl.cljc @@ -104,22 +104,24 @@ (defrecord Route [path matcher parts params meta result]) (defn create [[path meta result]] - (if (contains-wilds? path) - (as-> (parse-path path) $ - (assoc $ :path-re (path-regex $)) - (merge $ {:path path - :matcher (path-matcher $) - :result result - :meta meta}) - (dissoc $ :path-re :path-constraints) - (update $ :path-params set) - (set/rename-keys $ {:path-parts :parts - :path-params :params}) - (map->Route $)) - (map->Route {:path path - :meta meta - :matcher #(if (= path %) {}) - :result result}))) + (let [path #?(:clj (.intern ^String path) :cljs path)] + (if (contains-wilds? path) + (as-> (parse-path path) $ + (assoc $ :path-re (path-regex $)) + (merge $ {:path path + :matcher (path-matcher $) + :result result + :meta meta}) + (dissoc $ :path-re :path-constraints) + (update $ :path-params set) + (set/rename-keys $ {:path-parts :parts + :path-params :params}) + (map->Route $)) + (map->Route {:path path + :meta meta + :matcher #?(:clj #(if (.equals path %) {}) + :cljs #(if (= path %))) + :result result})))) (defn segments [path] (let [ss (-> (str/split path #"/") rest vec)]