mirror of
https://github.com/ruby/ruby.git
synced 2026-01-26 04:07:58 +00:00
[ruby/prism] Optimize ripper translator token sorting
With the benchmark from 2ea81398cc
Prism is:
* 1.33x slower before
* 1.07x slower after
https://github.com/ruby/prism/commit/a18b0acd80
This commit is contained in:
parent
b75938e2c3
commit
9269069e90
@ -802,8 +802,12 @@ module Prism
|
|||||||
# Drop the EOF token from the list
|
# Drop the EOF token from the list
|
||||||
tokens = tokens[0...-1]
|
tokens = tokens[0...-1]
|
||||||
|
|
||||||
# We sort by location to compare against Ripper's output
|
# We sort by location because Ripper.lex sorts.
|
||||||
tokens.sort_by!(&:location)
|
# Manually implemented instead of `sort_by!(&:location)` for performance.
|
||||||
|
tokens.sort_by! do |token|
|
||||||
|
line, column = token.location
|
||||||
|
source.line_to_byte_offset(line) + column
|
||||||
|
end
|
||||||
|
|
||||||
# Add :on_sp tokens
|
# Add :on_sp tokens
|
||||||
tokens = add_on_sp_tokens(tokens, source, result.data_loc, bom, eof_token)
|
tokens = add_on_sp_tokens(tokens, source, result.data_loc, bom, eof_token)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user