Skip to content

Commit

Permalink
Merge pull request #49 from amatsuda/perf1
Browse files Browse the repository at this point in the history
Prefer String#start_with? over Regexp.match
  • Loading branch information
tenderlove committed Feb 23, 2024
2 parents afc3704 + 054fe12 commit 75dc02f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ipaddr.rb
Expand Up @@ -674,7 +674,7 @@ def in_addr(addr)
end
octets.inject(0) { |i, s|
(n = s.to_i) < 256 or raise InvalidAddressError, "invalid address: #{@addr}"
s.match(/\A0./) and raise InvalidAddressError, "zero-filled number in IPv4 address is ambiguous: #{@addr}"
(s != '0') && s.start_with?('0') and raise InvalidAddressError, "zero-filled number in IPv4 address is ambiguous: #{@addr}"
i << 8 | n
}
end
Expand Down

0 comments on commit 75dc02f

Please sign in to comment.