Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(20)

Delta Between Two Patch Sets: Lib/ipaddress.py

Issue 21487: Assorted ipaddress performance improvements
Left Patch Set: Created 5 years, 8 months ago
Right Patch Set: Created 5 years, 8 months ago
 Left: Base Patch Set 1: None Patch Set 2: None Right: Patch Set 1: None Patch Set 2: None
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
LEFTRIGHT
2 # Licensed to PSF under a Contributor Agreement. 2 # Licensed to PSF under a Contributor Agreement.
3 3
4 """A fast, lightweight IPv4/IPv6 manipulation library in Python. 4 """A fast, lightweight IPv4/IPv6 manipulation library in Python.
5 5
6 This library is used to create/poke/manipulate IPv4 and IPv6 addresses 6 This library is used to create/poke/manipulate IPv4 and IPv6 addresses
7 and networks. 7 and networks.
8 8
9 """ 9 """
10 10
(...skipping 177 matching lines...)
188 Args: 188 Args:
189 number: an integer. 189 number: an integer.
190 bits: maximum number of bits to count. 190 bits: maximum number of bits to count.
191 191
192 Returns: 192 Returns:
193 The number of zero bits on the right hand side of the number. 193 The number of zero bits on the right hand side of the number.
194 194
195 """ 195 """
196 if number == 0: 196 if number == 0:
197 return bits 197 return bits
198 for i in range(0, bits, 8): 198 return min(bits, (~number & (number-1)).bit_length())
199 if number & 0xff:
200 while True:
201 if number & 1:
202 return min(bits, i)
203 number = number >> 1
204 i = i + 1
205 number = number >> 8
206 # All bits of interest were zero, even if there are more in the number
207 return bits
208 199
209 200
211 """Summarize a network range given the first and last IP addresses. 202 """Summarize a network range given the first and last IP addresses.
212 203
213 Example: 204 Example:
216 ... #doctest: +NORMALIZE_WHITESPACE 207 ... #doctest: +NORMALIZE_WHITESPACE
217 [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/31'), 208 [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/31'),
(...skipping 2033 matching lines...)
2251 Note that the site-local address space has been deprecated by RFC 3879. 2242 Note that the site-local address space has been deprecated by RFC 3879.
2252 Use is_private to test if this address is in the space of unique local 2243 Use is_private to test if this address is in the space of unique local
2253 addresses as defined by RFC 4193. 2244 addresses as defined by RFC 4193.
2254 2245
2255 Returns: 2246 Returns:
2256 A boolean, True if the address is reserved per RFC 3513 2.5.6. 2247 A boolean, True if the address is reserved per RFC 3513 2.5.6.
2257 2248
2258 """ 2249 """