Merge pull request #353 from wandersoncferreira/improvements/cleaning_boxed

adding type hints to clean boxed operations with java.lang.Objects
This commit is contained in:
Tommi Reiman 2020-01-19 10:44:06 +02:00 committed by GitHub
commit 904ce3db81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,7 +22,7 @@
(defprotocol Matcher (defprotocol Matcher
(match [this i max path]) (match [this i max path])
(view [this]) (view [this])
(depth [this]) (depth ^long [this])
(length [this])) (length [this]))
(defprotocol TrieCompiler (defprotocol TrieCompiler
@ -53,7 +53,7 @@
:else (recur (inc i)))))) :else (recur (inc i))))))
(defn- -keyword [s] (defn- -keyword [s]
(if-let [i (str/index-of s "/")] (if-let [^long i (str/index-of s "/")]
(keyword (subs s 0 i) (subs s (inc i))) (keyword (subs s 0 i) (subs s (inc i)))
(keyword s))) (keyword s)))
@ -61,8 +61,8 @@
(let [bracket? (-> syntax (into-set) :bracket) (let [bracket? (-> syntax (into-set) :bracket)
colon? (-> syntax (into-set) :colon) colon? (-> syntax (into-set) :colon)
-static (fn [from to] (if-not (= from to) [(subs s from to)])) -static (fn [from to] (if-not (= from to) [(subs s from to)]))
-wild (fn [from to] [(->Wild (-keyword (subs s (inc from) to)))]) -wild (fn [^long from to] [(->Wild (-keyword (subs s (inc from) to)))])
-catch-all (fn [from to] [(->CatchAll (keyword (subs s (inc from) to)))])] -catch-all (fn [^long from to] [(->CatchAll (keyword (subs s (inc from) to)))])]
(loop [ss nil, from 0, to 0] (loop [ss nil, from 0, to 0]
(if (= to (count s)) (if (= to (count s))
(concat ss (-static from to)) (concat ss (-static from to))
@ -70,13 +70,13 @@
(cond (cond
(and bracket? (= \{ c)) (and bracket? (= \{ c))
(let [to' (or (str/index-of s "}" to) (ex/fail! ::unclosed-brackets {:path s}))] (let [^long to' (or (str/index-of s "}" to) (ex/fail! ::unclosed-brackets {:path s}))]
(if (= \* (get s (inc to))) (if (= \* (get s (inc to)))
(recur (concat ss (-static from to) (-catch-all (inc to) to')) (long (inc to')) (long (inc to'))) (recur (concat ss (-static from to) (-catch-all (inc to) to')) (long (inc to')) (long (inc to')))
(recur (concat ss (-static from to) (-wild to to')) (long (inc to')) (long (inc to'))))) (recur (concat ss (-static from to) (-wild to to')) (long (inc to')) (long (inc to')))))
(and colon? (= \: c)) (and colon? (= \: c))
(let [to' (or (str/index-of s "/" to) (count s))] (let [^long to' (or (str/index-of s "/" to) (count s))]
(if (= 1 (- to' to)) (if (= 1 (- to' to))
(recur ss from (inc to)) (recur ss from (inc to))
(recur (concat ss (-static from to) (-wild to to')) (long to') (long to')))) (recur (concat ss (-static from to) (-wild to to')) (long to') (long to'))))
@ -115,7 +115,7 @@
(and (string? cp) (not= (count cp) (count p))) [(subs p (count cp))] (and (string? cp) (not= (count cp) (count p))) [(subs p (count cp))]
(and (string? p) (not cp)) (-split p))) (and (string? p) (not cp)) (-split p)))
-postcut (fn [[p :as pps]] -postcut (fn [[p :as pps]]
(let [i (and p (str/index-of p "/"))] (let [^long i (and p (str/index-of p "/"))]
(if (and i (pos? i)) (if (and i (pos? i))
(concat [(subs p 0 i) (subs p i)] (rest pps)) (concat [(subs p 0 i) (subs p i)] (rest pps))
pps))) pps)))
@ -128,7 +128,7 @@
(defn- -slice-end [x xs] (defn- -slice-end [x xs]
(let [i (if (string? x) (str/index-of x "/"))] (let [i (if (string? x) (str/index-of x "/"))]
(if (and (number? i) (pos? i)) (if (and (number? i) (pos? ^long i))
(concat [(subs x i)] xs) (concat [(subs x i)] xs)
xs))) xs)))
@ -227,11 +227,11 @@
(let [size (count path)] (let [size (count path)]
(reify Matcher (reify Matcher
(match [_ i max p] (match [_ i max p]
(if-not (< max (+ i size)) (if-not (< ^long max (+ ^long i size))
(loop [j 0] (loop [j 0]
(if (= j size) (if (= j size)
(match matcher (+ i size) max p) (match matcher (+ ^long i size) max p)
(if (= (get p (+ i j)) (get path j)) (if (= (get p (+ ^long i j)) (get path j))
(recur (inc j))))))) (recur (inc j)))))))
(view [_] [path (view matcher)]) (view [_] [path (view matcher)])
(depth [_] (inc (depth matcher))) (depth [_] (inc (depth matcher)))
@ -239,8 +239,8 @@
(wild-matcher [_ key end matcher] (wild-matcher [_ key end matcher]
(reify Matcher (reify Matcher
(match [_ i max path] (match [_ i max path]
(if (and (< i max) (not= (get path i) end)) (if (and (< ^long i ^long max) (not= (get path i) end))
(loop [percent? false, j i] (loop [percent? false, j ^long i]
(if (= max j) (if (= max j)
(if-let [match (match matcher max max path)] (if-let [match (match matcher max max path)]
(assoc-param match key (decode path i max percent?))) (assoc-param match key (decode path i max percent?)))
@ -257,7 +257,7 @@
(let [match (->Match params data)] (let [match (->Match params data)]
(reify Matcher (reify Matcher
(match [_ i max path] (match [_ i max path]
(if (<= i max) (assoc-param match key (decode path i max true)))) (if (<= ^long i ^long max) (assoc-param match key (decode path i max true))))
(view [_] [key [data]]) (view [_] [key [data]])
(depth [_] 1) (depth [_] 1)
(length [_])))) (length [_]))))
@ -271,7 +271,7 @@
(or (match (get matchers j) i max path) (or (match (get matchers j) i max path)
(recur (inc j)))))) (recur (inc j))))))
(view [_] (mapv view matchers)) (view [_] (mapv view matchers))
(depth [_] (inc (apply max 0 (map depth matchers)))) (depth [_] (inc ^long (apply max 0 (map depth matchers))))
(length [_])))) (length [_]))))
(-pretty [_ matcher] (-pretty [_ matcher]
(view matcher)) (view matcher))