summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2024-02-14 13:43:32 +0100
committergit <svn-admin@ruby-lang.org>2024-02-14 15:48:33 +0000
commitc2d8d6eba6a1c9e51c2f2ae136e92468c6841472 (patch)
tree2d84381667c743a0dc18ccf8df4675e3e958b29a /lib
parent1b2708b123038802740e58672e459fb6b575354c (diff)
Initialize the Prism::Source directly with all 3 fields for the C extension
* Faster that way: $ ruby -Ilib -rprism -rbenchmark/ips -e 'Benchmark.ips { |x| x.report("parse") { Prism.parse("1 + 2") } }' 195.722k (± 0.5%) i/s rb_iv_set(): 179.609k (± 0.5%) i/s rb_funcall(): 190.030k (± 0.3%) i/s before this PR: 183.319k (± 0.4%) i/s
Diffstat (limited to 'lib')
-rw-r--r--lib/prism/parse_result.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/prism/parse_result.rb b/lib/prism/parse_result.rb
index a3f588bb20..bcebc1a437 100644
--- a/lib/prism/parse_result.rb
+++ b/lib/prism/parse_result.rb
@@ -15,10 +15,10 @@ module Prism
attr_reader :offsets
# Create a new source object with the given source code.
- def initialize(source)
+ def initialize(source, start_line = 1, offsets = [])
@source = source
- @start_line = 1 # set after parsing is done
- @offsets = [] # set after parsing is done
+ @start_line = start_line # set after parsing is done
+ @offsets = offsets # set after parsing is done
end
# Perform a byteslice on the source code using the given byte offset and