From f2924015164b56f574217c35e054722a8a2963a5 Mon Sep 17 00:00:00 2001 From: xgfone Date: Mon, 18 Feb 2019 14:28:55 +0800 Subject: [PATCH] optimize the IPAddress and IPNetwork --- ipaddr.go | 2 +- ipnet.go | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/ipaddr.go b/ipaddr.go index 8632ecc..93d1d43 100644 --- a/ipaddr.go +++ b/ipaddr.go @@ -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. diff --git a/ipnet.go b/ipnet.go index dee2586..07e9564 100644 --- a/ipnet.go +++ b/ipnet.go @@ -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 @@ -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