Skip to content

Commit

Permalink
Use sub instead of gsub when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
stomar committed Jan 1, 2024
1 parent f546428 commit a8128da
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/pnm/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def self.convert_to_integers(data, type)
values_as_string = if type == :pbm
data.gsub(/[ \t\r\n]+/, "").chars
else
data.gsub(/\A[ \t\r\n]+/, "").split(/[ \t\r\n]+/)
data.sub(/\A[ \t\r\n]+/, "").split(/[ \t\r\n]+/)
end

values_as_string.map {|value| Integer(value) }
Expand Down
6 changes: 3 additions & 3 deletions lib/pnm/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.parse(content)
token = next_token!(content)

if token.start_with?("#")
comments << token.gsub(/# */, "")
comments << token.sub(/# */, "")
else
magic_number = token
end
Expand All @@ -38,11 +38,11 @@ def self.parse(content)
assert_valid_magic_number(magic_number)

while tokens.size < token_number[magic_number]
content.gsub!(/\A[ \t\r\n]+/, "")
content.sub!(/\A[ \t\r\n]+/, "")
token = next_token!(content)

if token.start_with?("#")
comments << token.gsub(/# */, "")
comments << token.sub(/# */, "")
else
tokens << token
end
Expand Down

0 comments on commit a8128da

Please sign in to comment.