summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Nordhausen <stefan.nordhausen@immobilienscout24.de>2015-06-09 12:41:58 +0200
committerStefan Nordhausen <stefan.nordhausen@immobilienscout24.de>2015-06-09 12:41:58 +0200
commit7b9093f4a2bb539007c4bc8d2a2d7464f23f9350 (patch)
tree58212110da3f856942e0c6dd2c8b81d2772f3bf3
parent8dec0a49a10a82172b4cb7e923f1a6dbfcbcf7fb (diff)
downloadnetaddr-7b9093f4a2bb539007c4bc8d2a2d7464f23f9350.tar.gz
Issue 94: Make IPSet.__contains__ faster
-rw-r--r--CHANGELOG18
-rw-r--r--netaddr/ip/sets.py9
2 files changed, 23 insertions, 4 deletions
diff --git a/CHANGELOG b/CHANGELOG
index dd6be38..ec182ab 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,22 @@
---------------
+Release: 0.7.15
+---------------
+Date: ?????????
+
+^^^^^^^^^^^^^^^^^^^^
+Changes since 0.7.14
+^^^^^^^^^^^^^^^^^^^^
+
+* Fix slowness in IPSet.__contains__. Thanks to novas0x2a for noticing.
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Specific bug fixes addressed in this release
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+FIXED Issue 94: https://github.com/drkjam/netaddr/issues/94
+ - IPSet.__contains__ is about 40 times slower than the equivalent IPRange
+
+---------------
Release: 0.7.14
---------------
Date: 31st Mar 2015
diff --git a/netaddr/ip/sets.py b/netaddr/ip/sets.py
index 204ffd2..70f44cf 100644
--- a/netaddr/ip/sets.py
+++ b/netaddr/ip/sets.py
@@ -231,15 +231,16 @@ class IPSet(object):
:return: ``True`` if IP address or subnet is a member of this IP set.
"""
- ip = IPNetwork(ip)
# Iterating over self._cidrs is an O(n) operation: 1000 items in
# self._cidrs would mean 1000 loops. Iterating over all possible
# supernets loops at most 32 times for IPv4 or 128 times for IPv6,
# no matter how many CIDRs this object contains.
- if ip in self._cidrs:
+ supernet = IPNetwork(ip)
+ if supernet in self._cidrs:
return True
- for cidr in ip.supernet():
- if cidr in self._cidrs:
+ while supernet._prefixlen:
+ supernet._prefixlen -= 1
+ if supernet in self._cidrs:
return True
return False