diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2018-02-15 11:40:14 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-15 11:40:14 -0800 |
commit | 9f65d2a08bc80a94bbb2c0b6e00957c7059aed25 (patch) | |
tree | 65d287b1bb5f8601d4ae6149e2a5c5611c7b5649 | |
parent | 966843732a607864b077b72b2a17168d4e3548cc (diff) | |
parent | 24131d4a6a97621c1021231c650793ce29c4ed99 (diff) | |
download | rails-9f65d2a08bc80a94bbb2c0b6e00957c7059aed25.tar.gz rails-9f65d2a08bc80a94bbb2c0b6e00957c7059aed25.tar.bz2 rails-9f65d2a08bc80a94bbb2c0b6e00957c7059aed25.zip |
Merge pull request #31999 from SamSaffron/patch-1
PERF: dedupe scanned route fragments
-rw-r--r-- | actionpack/lib/action_dispatch/journey/scanner.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/journey/scanner.rb b/actionpack/lib/action_dispatch/journey/scanner.rb index 4ae77903fa..5ed587c1b1 100644 --- a/actionpack/lib/action_dispatch/journey/scanner.rb +++ b/actionpack/lib/action_dispatch/journey/scanner.rb @@ -33,6 +33,13 @@ module ActionDispatch end private + + # takes advantage of String @- deduping capabilities in Ruby 2.5 upwards + # see: https://bugs.ruby-lang.org/issues/13077 + def dedup_scan(regex) + r = @ss.scan(regex) + r ? -r : nil + end def scan case @@ -47,15 +54,15 @@ module ActionDispatch [:OR, "|"] when @ss.skip(/\./) [:DOT, "."] - when text = @ss.scan(/:\w+/) + when text = dedup_scan(/:\w+/) [:SYMBOL, text] - when text = @ss.scan(/\*\w+/) + when text = dedup_scan(/\*\w+/) [:STAR, text] - when text = @ss.scan(/(?:[\w%\-~!$&'*+,;=@]|\\[:()])+/) + when text = dedup_scan(/(?:[\w%\-~!$&'*+,;=@]|\\[:()])+/) text.tr! "\\", "" [:LITERAL, text] # any char - when text = @ss.scan(/./) + when text = dedup_scan(/./) [:LITERAL, text] end end |