Skip to content

Commit

Permalink
optimize the IPAddress and IPNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
xgfone committed Feb 18, 2019
1 parent b76917e commit f292401
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ipaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (ip IPAddress) Compare(other IPAddress) int {

// Less reports whether ip is less than other.
func (ip IPAddress) Less(other IPAddress) bool {
return ip.BigInt().Cmp(other.BigInt()) < 0
return ip.Compare(other) < 0
}

// IsIPv4 reports whether the ip address is ipv4.
Expand Down
8 changes: 2 additions & 6 deletions ipnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,7 @@ func (net IPNetwork) Contains(other IPNetwork) bool {
return false
}

if net.First().BigInt().Cmp(other.First().BigInt()) <= 0 &&
other.Last().BigInt().Cmp(net.Last().BigInt()) <= 0 {
if net.first.Compare(other.first) <= 0 && other.first.Compare(net.last) <= 0 {
return true
}
return false
Expand All @@ -486,10 +485,7 @@ func (net IPNetwork) HasIP(ip IPAddress) bool {
return false
}

first := net.First().BigInt()
last := net.Last().BigInt()
value := ip.BigInt()
if first.Cmp(value) <= 0 && value.Cmp(last) <= 0 {
if net.first.Compare(ip) <= 0 && ip.Compare(net.last) <= 0 {
return true
}
return false
Expand Down

0 comments on commit f292401

Please sign in to comment.