1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/ipaddr.rb (in_addr, in6_addr, addr_mask): Make some minor

code optimization.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13629 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2007-10-04 19:03:56 +00:00
parent 2a3528a051
commit 228bb8ea4c
2 changed files with 11 additions and 14 deletions

View file

@ -1,3 +1,8 @@
Fri Oct 5 04:02:39 2007 Akinori MUSHA <knu@iDaemons.org>
* lib/ipaddr.rb (in_addr, in6_addr, addr_mask): Make some minor
code optimization.
Fri Oct 5 03:25:51 2007 Akinori MUSHA <knu@iDaemons.org>
* lib/ipaddr.rb (<=>): Implement IPAddr#<=> and make IPAddr

View file

@ -496,12 +496,9 @@ class IPAddr
def in_addr(addr)
if addr =~ /^\d+\.\d+\.\d+\.\d+$/
n = 0
addr.split('.').each { |i|
n <<= 8
n += i.to_i
return addr.split('.').inject(0) { |i, s|
i << 8 | s.to_i
}
return n
end
return nil
end
@ -525,25 +522,20 @@ class IPAddr
if rest < 0
return nil
end
a = [l, Array.new(rest, '0'), r].flatten!
n = 0
a.each { |i|
n <<= 16
n += i.hex
return (l + Array.new(rest, '0') + r).inject(0) { |i, s|
i << 16 | s.hex
}
return n
end
def addr_mask(addr)
case @family
when Socket::AF_INET
addr &= IN4MASK
return addr & IN4MASK
when Socket::AF_INET6
addr &= IN6MASK
return addr & IN6MASK
else
raise "unsupported address family"
end
return addr
end
def _reverse