Skip to content

Commit 3bbcc92

Browse files
gescheitmethane
authored andcommitted
bpo-25430: improve performance of IPNetwork.__contains__ (GH-1785)
make a compare in bit-operation manner.
1 parent b0a2c0f commit 3bbcc92

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Lib/ipaddress.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,7 @@ def __contains__(self, other):
697697
# dealing with another address
698698
else:
699699
# address
700-
return (int(self.network_address) <= int(other._ip) <=
701-
int(self.broadcast_address))
700+
return other._ip & self.netmask._ip == self.network_address._ip
702701

703702
def overlaps(self, other):
704703
"""Tell if self is partly contained in other."""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
improve performance of ``IPNetwork.__contains__()``

0 commit comments

Comments
 (0)