Skip to content

Commit 0e1c05c

Browse files
authored
Merge pull request #3870 from Earlopain/ripper-translator-optimize-sort
Optimize ripper translator token sorting
2 parents 61e1207 + a18b0ac commit 0e1c05c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/prism/lex_compat.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,12 @@ def result
802802
# Drop the EOF token from the list
803803
tokens = tokens[0...-1]
804804

805-
# We sort by location to compare against Ripper's output
806-
tokens.sort_by!(&:location)
805+
# We sort by location because Ripper.lex sorts.
806+
# Manually implemented instead of `sort_by!(&:location)` for performance.
807+
tokens.sort_by! do |token|
808+
line, column = token.location
809+
source.line_to_byte_offset(line) + column
810+
end
807811

808812
# Add :on_sp tokens
809813
tokens = add_on_sp_tokens(tokens, source, result.data_loc, bom, eof_token)

0 commit comments

Comments
 (0)