Skip to content

Commit e0feb07

Browse files
committed
String#split seems to be faster than capturing digits with Regexp
1 parent d92acb3 commit e0feb07

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎lib/ipaddr.rb‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class IPAddr
5252
# Regexp _internally_ used for parsing IPv4 address.
5353
RE_IPV4ADDRLIKE = %r{
5454
\A
55-
(\d+) \. (\d+) \. (\d+) \. (\d+)
55+
\d+ \. \d+ \. \d+ \. \d+
5656
\z
5757
}x
5858

@@ -647,8 +647,8 @@ def in_addr(addr)
647647
when Array
648648
octets = addr
649649
else
650-
m = RE_IPV4ADDRLIKE.match(addr) or return nil
651-
octets = m.captures
650+
RE_IPV4ADDRLIKE.match?(addr) or return nil
651+
octets = addr.split('.')
652652
end
653653
octets.inject(0) { |i, s|
654654
(n = s.to_i) < 256 or raise InvalidAddressError, "invalid address: #{@addr}"

0 commit comments

Comments
 (0)