mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Reduce allocations and retentions in Journey TransitionTable
`DEFAULT_EXP` is by far the most common regexp being anchored. By special casing it, we can re-use the existing `DEFAULT_EXP_ANCHORED` regexp, and avoid keeping lots of copies of it in memory. Every time we hit, we also avoid having to compile the regexp, so it's faster. We also replace the `Regexp.new(/\A#{sym}\Z/)` pattern by just `/\A#{sym}\Z/`, as it was compiling and instantiating an extra regexp for no good reason.
This commit is contained in:
parent
c3664b0c2b
commit
e2a83cd9bd
1 changed files with 6 additions and 2 deletions
|
@ -11,7 +11,7 @@ module ActionDispatch
|
|||
attr_reader :memos
|
||||
|
||||
DEFAULT_EXP = /[^.\/?]+/
|
||||
DEFAULT_EXP_ANCHORED = Regexp.new(/\A#{DEFAULT_EXP}\Z/)
|
||||
DEFAULT_EXP_ANCHORED = /\A#{DEFAULT_EXP}\Z/
|
||||
|
||||
def initialize
|
||||
@stdparam_states = {}
|
||||
|
@ -165,7 +165,11 @@ module ActionDispatch
|
|||
case sym
|
||||
when Regexp
|
||||
# we must match the whole string to a token boundary
|
||||
sym = Regexp.new(/\A#{sym}\Z/)
|
||||
if sym == DEFAULT_EXP
|
||||
sym = DEFAULT_EXP_ANCHORED
|
||||
else
|
||||
sym = /\A#{sym}\Z/
|
||||
end
|
||||
when Symbol
|
||||
# account for symbols in the constraints the same as strings
|
||||
sym = sym.to_s
|
||||
|
|
Loading…
Reference in a new issue