Memoize regex when checking missing route keys
When the route definition has parameters, we can supply a regex for validation purposes: get "/a/:b" => "test#index", constraints: { b: /abc/ }, as: test This regex is going to be used to check the supplied values during link generation: test_path("abc") # check "abc" against /abc/ regex The link generation code checks each parameter. To properly validate the parameter, it creates a new regex with start and end of string modifiers: /\A#{original_regex}\Z/ This means for each link generation the code stringifies the existing regex and creates a new one. When a new regex is created, it needs to be compiled, for large regexes this can take quite a bit of time. This change memoizes the generated regex for each route when constrains are given. It also removes the RegexCaseComparator class since it is not in use anymore.
Showing
想要评论请 注册 或 登录