Fast path matching with .equals

This commit is contained in:
Tommi Reiman 2017-10-02 08:07:15 +03:00
parent 40c35a0dfd
commit da9c94e520

View file

@ -104,22 +104,24 @@
(defrecord Route [path matcher parts params meta result]) (defrecord Route [path matcher parts params meta result])
(defn create [[path meta result]] (defn create [[path meta result]]
(if (contains-wilds? path) (let [path #?(:clj (.intern ^String path) :cljs path)]
(as-> (parse-path path) $ (if (contains-wilds? path)
(assoc $ :path-re (path-regex $)) (as-> (parse-path path) $
(merge $ {:path path (assoc $ :path-re (path-regex $))
:matcher (path-matcher $) (merge $ {:path path
:result result :matcher (path-matcher $)
:meta meta}) :result result
(dissoc $ :path-re :path-constraints) :meta meta})
(update $ :path-params set) (dissoc $ :path-re :path-constraints)
(set/rename-keys $ {:path-parts :parts (update $ :path-params set)
:path-params :params}) (set/rename-keys $ {:path-parts :parts
(map->Route $)) :path-params :params})
(map->Route {:path path (map->Route $))
:meta meta (map->Route {:path path
:matcher #(if (= path %) {}) :meta meta
:result result}))) :matcher #?(:clj #(if (.equals path %) {})
:cljs #(if (= path %)))
:result result}))))
(defn segments [path] (defn segments [path]
(let [ss (-> (str/split path #"/") rest vec)] (let [ss (-> (str/split path #"/") rest vec)]