summaryrefslogtreecommitdiff
path: root/lib/prism/parse_result.rb
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2024-02-15 13:41:40 -0500
committergit <[email protected]>2024-02-15 20:39:50 +0000
commit14a7277da13f4c082850cb30c36f4458b6fd35d1 ()
tree1cf18bcdc5748efafaf042b046fbb0f349d669eb /lib/prism/parse_result.rb
parent87cc2fd015fa7f840ae53bb58472354da754b44d (diff)
[ruby/prism] Speed up creating Ruby AST
When creating the Ruby AST, we were previously allocating Location objects for every node and every inner location. Instead, this commit changes it to pack both the start offset and length into a single u64 and pass that into the nodes. Then, when the locations are requested via a reader method, we lazily allocate the Location objects. https://.com/ruby/prism/commit/de203dca83 Co-Authored-By: Aaron Patterson <[email protected]>
-rw-r--r--lib/prism/parse_result.rb16
1 files changed, 12 insertions, 4 deletions
@@ -452,17 +452,19 @@ module Prism
# This represents a token from the Ruby source.
class Token
# The type of token that this token is.
attr_reader :type
# A byteslice of the source that this token represents.
attr_reader :value
- # A Location object representing the location of this token in the source.
- attr_reader :location
-
# Create a new token object with the given type, value, and location.
- def initialize(type, value, location)
@type = type
@value = value
@location = location
@@ -473,6 +475,12 @@ module Prism
{ type: type, value: value, location: location }
end
# Implement the pretty print interface for Token.
def pretty_print(q)
q.group do