[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / lib / syntax_suggest / unvisited_lines.rb
blob32808db63402aef6b6fc9f77bdff4158571468d2
1 # frozen_string_literal: true
3 module SyntaxSuggest
4   # Tracks which lines various code blocks have expanded to
5   # and which are still unexplored
6   class UnvisitedLines
7     def initialize(code_lines:)
8       @unvisited = code_lines.sort_by(&:indent_index)
9       @visited_lines = {}
10       @visited_lines.compare_by_identity
11     end
13     def empty?
14       @unvisited.empty?
15     end
17     def peek
18       @unvisited.last
19     end
21     def pop
22       @unvisited.pop
23     end
25     def visit_block(block)
26       block.lines.each do |line|
27         next if @visited_lines[line]
28         @visited_lines[line] = true
29       end
31       while @visited_lines[@unvisited.last]
32         @unvisited.pop
33       end
34     end
35   end
36 end