]> granicus.if.org Git - python/commitdiff
bpo-25430: improve performance of IPNetwork.__contains__ (GH-1785)
authorgescheit <gescheit12@gmail.com>
Tue, 30 Apr 2019 07:54:30 +0000 (10:54 +0300)
committerInada Naoki <songofacandy@gmail.com>
Tue, 30 Apr 2019 07:54:30 +0000 (16:54 +0900)
make a compare in bit-operation manner.

Lib/ipaddress.py
Misc/NEWS.d/next/Library/2019-04-15-12-22-09.bpo-25430.7_8kqc.rst [new file with mode: 0644]

index 909a55de4f197d0668c1150bb732251b7db0850d..662d7373890761b637c8cb284c75d30262be462b 100644 (file)
@@ -697,8 +697,7 @@ class _BaseNetwork(_IPAddressBase):
         # dealing with another address
         else:
             # address
-            return (int(self.network_address) <= int(other._ip) <=
-                    int(self.broadcast_address))
+            return other._ip & self.netmask._ip == self.network_address._ip
 
     def overlaps(self, other):
         """Tell if self is partly contained in other."""
diff --git a/Misc/NEWS.d/next/Library/2019-04-15-12-22-09.bpo-25430.7_8kqc.rst b/Misc/NEWS.d/next/Library/2019-04-15-12-22-09.bpo-25430.7_8kqc.rst
new file mode 100644 (file)
index 0000000..922bdef
--- /dev/null
@@ -0,0 +1 @@
+improve performance of ``IPNetwork.__contains__()``
\ No newline at end of file