mirror of
https://github.com/ruby/ruby.git
synced 2026-01-26 20:19:19 +00:00
[ruby/prism] Simplify and optimize Prism::Node#tunnel
* By comparing byte offsets which folds 3 branches into 1. * Also avoids allocation of Location objects. https://github.com/ruby/prism/commit/71fcb891e0
This commit is contained in:
parent
e85fd7c878
commit
ae5efb55d1
@ -184,24 +184,14 @@ module Prism
|
||||
queue = [self] #: Array[Prism::node]
|
||||
result = [] #: Array[Prism::node]
|
||||
|
||||
line_offset = source.offsets[line - 1] or raise
|
||||
search_offset = line_offset + column
|
||||
|
||||
while (node = queue.shift)
|
||||
result << node
|
||||
|
||||
node.each_child_node do |child_node|
|
||||
child_location = child_node.location
|
||||
|
||||
start_line = child_location.start_line
|
||||
end_line = child_location.end_line
|
||||
|
||||
if start_line == end_line
|
||||
if line == start_line && column >= child_location.start_column && column < child_location.end_column
|
||||
queue << child_node
|
||||
break
|
||||
end
|
||||
elsif (line == start_line && column >= child_location.start_column) || (line == end_line && column < child_location.end_column)
|
||||
queue << child_node
|
||||
break
|
||||
elsif line > start_line && line < end_line
|
||||
if child_node.start_offset <= search_offset && search_offset < child_node.end_offset
|
||||
queue << child_node
|
||||
break
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user