instance method
Prism::CodeUnitsCache#[]
[](byte_offset)
lib/prism/parse_result.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/prism/parse_result.rb, line 217
def [](byte_offset)
@cache[byte_offset] ||=
if (index = @offsets.bsearch_index { |offset| offset > byte_offset }).nil?
@offsets << byte_offset
@counter.count(0, byte_offset)
elsif index == 0
@offsets.unshift(byte_offset)
@counter.count(0, byte_offset)
else
@offsets.insert(index, byte_offset)
offset = @offsets[index - 1]
@cache[offset] + @counter.count(offset, byte_offset - offset)
end
end
Retrieve the code units offset from the given byte offset.