Skip to content

Commit

Permalink
Remove all uses of reflection from route matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
amalloy committed May 25, 2012
1 parent b1f93e9 commit 4647aea
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/clout/core.clj
Expand Up @@ -2,6 +2,7 @@
"Library for parsing the Rails routes syntax."
(:require [clojure.string :as string])
(:import java.util.Map
java.util.regex.Matcher
[java.net URLDecoder URLEncoder]))

;; Regular expression utilties
Expand All @@ -19,9 +20,9 @@
(defn re-groups*
"More consistant re-groups that always returns a vector of groups, even if
there is only one group."
[matcher]
[^Matcher matcher]
(for [i (range (.groupCount matcher))]
(.group matcher (inc i))))
(.group matcher (int (inc i)))))

;; Route matching

Expand Down Expand Up @@ -94,7 +95,7 @@
(let [matcher (re-matcher re src)]
(if (.lookingAt matcher)
[(if (fn? action) (action matcher) action)
(.substring src (.end matcher))])))
(subs src (.end matcher))])))
(partition 2 clauses)))

(defn- lex
Expand Down Expand Up @@ -123,15 +124,15 @@
(let [splat #"\*"
word #":([\p{L}_][\p{L}_0-9-]*)"
literal #"(:[^\p{L}_*]|[^:*])+"
word-group #(keyword (.group % 1))
word-group #(keyword (.group ^Matcher % 1))
word-regex #(regexs (word-group %) "[^/,;?]+")]
(CompiledRoute.
(re-pattern
(apply str
(lex path
splat "(.*?)"
word #(str "(" (word-regex %) ")")
literal #(re-escape (.group %)))))
literal #(re-escape (.group ^Matcher %)))))
(remove nil?
(lex path
splat :*
Expand Down

0 comments on commit 4647aea

Please sign in to comment.