Skip to content

Commit

Permalink
Fix some syntax warnings and some allocation specs
Browse files Browse the repository at this point in the history
  • Loading branch information
kputnam committed Sep 25, 2019
1 parent 925c777 commit 4a86e4f
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 146 deletions.
3 changes: 3 additions & 0 deletions lib/stupidedi/reader/pointer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ def inspect
# This operation typically allocates memory and copies part of @storage,
# so this is avoided as much as possible.
#
# Unless the optional parameter `always_allocate` is `true`, then the
# return value may be `#frozen?` in some cases.
#
# @return [S]
def reify(always_allocate = false)
if @storage.frozen? \
Expand Down
3 changes: 2 additions & 1 deletion lib/stupidedi/reader/substring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def count(other)
# substring pointer.
#
# @return [self]
Z = "abc"
def <<(other)
case other
when self.class
Expand All @@ -185,7 +186,7 @@ def <<(other)
@length += other.length
elsif not @storage.frozen?
# Surely no one will notice if we destructively update @storage
@storage[@offset + @length, @storage.length - @offset - @length] = other
@storage[@offset + @length, @storage.length - @offset - @length] = other.reify
@length += other.length
else
# Other pointers are sharing our storage. We need to make our own
Expand Down
2 changes: 1 addition & 1 deletion lib/stupidedi/reader/tokenizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def _update_state(segment_tok, config)
gscode = version.try(:slice, 0, 6)

# GS01: Functional Identifier Code
fgcode = segment_tok.element_toks.at(0).try(:value)
# fgcode = segment_tok.element_toks.at(0).try(:value)

if config.functional_group.defined_at?(gscode)
envelope_def = config.functional_group.at(gscode)
Expand Down
1 change: 1 addition & 0 deletions lib/stupidedi/ruby/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def match?(pattern, pos=nil)
if pos.nil?
!!(self =~ pattern)
else
# NOTE: Regexp#match allocates a MatchData, String#match does not
!!match(pattern, pos)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/stupidedi/reader/native_ext_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
expect(extend_language).to be_graphic(encoding: e)
end

if n = e[/iso-8859-(\d+)/, 1].try{|n| Integer(n) }
if n = e[/iso-8859-(\d+)/, 1].try{|m| Integer(m) }
it "identifies all graphic characters" do
bytes = iso_8859_table.reject{|_, no| no.include?(n) }.keys
string = bytes.sort.map(&:chr).join.force_encoding(e)
Expand Down
11 changes: 8 additions & 3 deletions spec/lib/stupidedi/reader/pointer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# frozen_string_literal: true
# frozen_string_literal: false

describe Stupidedi::Reader::Pointer do
using Stupidedi::Refinements

def pointer(value)
Stupidedi::Reader::Pointer.build(value)
def pointer(string, frozen: nil)
frozen = [true, false].sample if frozen.nil?
string.freeze if frozen and not string.frozen?
string = string.dup if not frozen and string.frozen?
Stupidedi::Reader::Pointer.build(string)
end


def pointer_(*args)
Stupidedi::Reader::Pointer.new(args)
end
Expand Down
Loading

0 comments on commit 4a86e4f

Please sign in to comment.