From 3bbcc92577f8e616bc94c679040043bacd00ebf1 Mon Sep 17 00:00:00 2001 From: gescheit Date: Tue, 30 Apr 2019 10:54:30 +0300 Subject: [PATCH] bpo-25430: improve performance of IPNetwork.__contains__ (GH-1785) make a compare in bit-operation manner. --- Lib/ipaddress.py | 3 +-- .../next/Library/2019-04-15-12-22-09.bpo-25430.7_8kqc.rst | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2019-04-15-12-22-09.bpo-25430.7_8kqc.rst diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index 909a55de4f..662d737389 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -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 index 0000000000..922bdef56e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-04-15-12-22-09.bpo-25430.7_8kqc.rst @@ -0,0 +1 @@ +improve performance of ``IPNetwork.__contains__()`` \ No newline at end of file -- 2.50.1