File tree 3 files changed +22
-18
lines changed
modules/reitit-core/src/reitit
3 files changed +22
-18
lines changed Original file line number Diff line number Diff line change 74
74
coerce (into [] (keep #(coerce % opts)))))
75
75
76
76
(defn path-conflicting-routes [routes opts]
77
- (-> (into {}
78
- (comp (map-indexed (fn [index route]
79
- [route (into #{}
80
- (filter #(trie/conflicting-paths? (first route) (first %) opts))
81
- (subvec routes (inc index)))]))
82
- (filter (comp seq second)))
83
- routes)
84
- (not-empty )))
77
+ (let [parts-and-routes (mapv (fn [[s :as r]] [(trie/split-path s opts) r]) routes)]
78
+ (-> (into {} (comp (map-indexed (fn [index [p r]]
79
+ [r (reduce
80
+ (fn [acc [p' r']]
81
+ (if (trie/conflicting-parts? p p')
82
+ (conj acc r') acc))
83
+ #{} (subvec parts-and-routes (inc index)))]))
84
+ (filter (comp seq second))) parts-and-routes)
85
+ (not-empty ))))
85
86
86
87
(defn unresolved-conflicts [path-conflicting]
87
88
(-> (into {}
Original file line number Diff line number Diff line change 132
132
(concat [(subs x i)] xs)
133
133
xs)))
134
134
135
+ (defn conflicting-parts? [parts1 parts2]
136
+ (let [[[s1 & ss1] [s2 & ss2]] (-slice-start parts1 parts2)]
137
+ (cond
138
+ (= s1 s2 nil ) true
139
+ (or (nil? s1) (nil? s2)) false
140
+ (or (catch-all? s1) (catch-all? s2)) true
141
+ (or (wild? s1) (wild? s2)) (recur (-slice-end s1 ss1) (-slice-end s2 ss2))
142
+ (not= s1 s2) false
143
+ :else (recur ss1 ss2))))
144
+
135
145
(defn conflicting-paths? [path1 path2 opts]
136
- (loop [parts1 (split-path path1 opts)
137
- parts2 (split-path path2 opts)]
138
- (let [[[s1 & ss1] [s2 & ss2]] (-slice-start parts1 parts2)]
139
- (cond
140
- (= s1 s2 nil ) true
141
- (or (nil? s1) (nil? s2)) false
142
- (or (catch-all? s1) (catch-all? s2)) true
143
- (or (wild? s1) (wild? s2)) (recur (-slice-end s1 ss1) (-slice-end s2 ss2))
144
- (not= s1 s2) false
145
- :else (recur ss1 ss2)))))
146
+ (conflicting-parts? (split-path path1 opts) (split-path path2 opts)))
146
147
147
148
; ;
148
149
; ; Creating Tries
Original file line number Diff line number Diff line change 40
40
(suite " non-conflicting" )
41
41
42
42
; ; 104ms
43
+ ; ; 11ms (reuse parts in conflict resolution)
43
44
(bench! " default" (r/router hundred-routes))
44
45
45
46
; ; 7ms
50
51
51
52
; ; 205ms
52
53
; ; 105ms (cache path-conflicts)
54
+ ; ; 13ms (reuse parts in conflict resolution)
53
55
(bench! " default" (r/router routes {:conflicts nil }))))
54
56
55
57
(comment
You can’t perform that action at this time.
0 commit comments