diff options
author | Matthew Draper <matthew@trebex.net> | 2016-12-25 01:03:02 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-12-25 01:04:08 +1030 |
commit | 4273ab34c484f38fa9f77d133cd83256d721e7c8 (patch) | |
tree | b1510a1c9b8f492e1ded5f52b14ceae8ab646dad /actionpack/lib/action_dispatch/journey/scanner.rb | |
parent | fc2aa53f875b12df93b0d07932e3ab563b89152c (diff) | |
download | rails-4273ab34c484f38fa9f77d133cd83256d721e7c8.tar.gz rails-4273ab34c484f38fa9f77d133cd83256d721e7c8.tar.bz2 rails-4273ab34c484f38fa9f77d133cd83256d721e7c8.zip |
Shave a couple of allocations off Journey scan & parse
Diffstat (limited to 'actionpack/lib/action_dispatch/journey/scanner.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/journey/scanner.rb | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/actionpack/lib/action_dispatch/journey/scanner.rb b/actionpack/lib/action_dispatch/journey/scanner.rb index 4b8c8ab063..7dbb39b26d 100644 --- a/actionpack/lib/action_dispatch/journey/scanner.rb +++ b/actionpack/lib/action_dispatch/journey/scanner.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "strscan" module ActionDispatch @@ -35,22 +36,23 @@ module ActionDispatch def scan case # / - when text = @ss.scan(/\//) - [:SLASH, text] + when @ss.skip(/\//) + [:SLASH, "/"] + when @ss.skip(/\(/) + [:LPAREN, "("] + when @ss.skip(/\)/) + [:RPAREN, ")"] + when @ss.skip(/\|/) + [:OR, "|"] + when @ss.skip(/\./) + [:DOT, "."] + when text = @ss.scan(/:\w+/) + [:SYMBOL, text] when text = @ss.scan(/\*\w+/) [:STAR, text] - when text = @ss.scan(/(?<!\\)\(/) - [:LPAREN, text] - when text = @ss.scan(/(?<!\\)\)/) - [:RPAREN, text] - when text = @ss.scan(/\|/) - [:OR, text] - when text = @ss.scan(/\./) - [:DOT, text] - when text = @ss.scan(/(?<!\\):\w+/) - [:SYMBOL, text] - when text = @ss.scan(/(?:[\w%\-~!$&'*+,;=@]|\\:|\\\(|\\\))+/) - [:LITERAL, text.tr('\\', "")] + when text = @ss.scan(/(?:[\w%\-~!$&'*+,;=@]|\\[:()])+/) + text.tr! "\\", "" + [:LITERAL, text] # any char when text = @ss.scan(/./) [:LITERAL, text] |