lib/prism/serialize.rb in prism-0.22.0 vs lib/prism/serialize.rb in prism-0.23.0
- old
+ new
@@ -25,11 +25,11 @@
# strings.
MAJOR_VERSION = 0
# The minor version of prism that we are expecting to find in the serialized
# strings.
- MINOR_VERSION = 22
+ MINOR_VERSION = 23
# The patch version of prism that we are expecting to find in the serialized
# strings.
PATCH_VERSION = 0
@@ -84,29 +84,33 @@
@input = input.force_encoding(@encoding).freeze
@encoding
end
def load_start_line
- source.start_line = load_varsint
+ source.instance_variable_set :@start_line, load_varsint
end
+ def load_line_offsets
+ source.instance_variable_set :@offsets, Array.new(load_varuint) { load_varuint }
+ end
+
def load_comments
- load_varuint.times.map do
+ Array.new(load_varuint) do
case load_varuint
when 0 then InlineComment.new(load_location)
when 1 then EmbDocComment.new(load_location)
when 2 then DATAComment.new(load_location)
end
end
end
def load_metadata
comments = load_comments
- magic_comments = load_varuint.times.map { MagicComment.new(load_location, load_location) }
+ magic_comments = Array.new(load_varuint) { MagicComment.new(load_location, load_location) }
data_loc = load_optional_location
- errors = load_varuint.times.map { ParseError.new(load_embedded_string, load_location, load_error_level) }
- warnings = load_varuint.times.map { ParseWarning.new(load_embedded_string, load_location, load_warning_level) }
+ errors = Array.new(load_varuint) { ParseError.new(load_embedded_string, load_location, load_error_level) }
+ warnings = Array.new(load_varuint) { ParseWarning.new(load_embedded_string, load_location, load_warning_level) }
[comments, magic_comments, data_loc, errors, warnings]
end
def load_tokens
tokens = []
@@ -123,10 +127,11 @@
def load_tokens_result
tokens = load_tokens
encoding = load_encoding
load_start_line
+ load_line_offsets
comments, magic_comments, data_loc, errors, warnings = load_metadata
tokens.each { |token,| token.value.force_encoding(encoding) }
raise "Expected to consume all bytes while deserializing" unless @io.eof?
Prism::ParseResult.new(tokens, comments, magic_comments, data_loc, errors, warnings, @source)
@@ -134,9 +139,10 @@
def load_nodes
load_header
load_encoding
load_start_line
+ load_line_offsets
comments, magic_comments, data_loc, errors, warnings = load_metadata
@constant_pool_offset = io.read(4).unpack1("L")
@constant_pool = Array.new(load_varuint, nil)