Content-Length: 278417 | pFad | http://github.com/python/cpython/commit/3a639bbeace73d54f7e5431d3224c8c8223d81ae

2F Improve speed. Reduce auxiliary memory to 16.6% of the main array. (G… · python/cpython@3a639bb · GitHub
Skip to content

Commit 3a639bb

Browse files
authored
Improve speed. Reduce auxiliary memory to 16.6% of the main array. (GH-98294)
1 parent 11c25a4 commit 3a639bb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Doc/library/itertools.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -822,12 +822,13 @@ which incur interpreter overhead.
822822
def sieve(n):
823823
"Primes less than n"
824824
# sieve(30) --> 2 3 5 7 11 13 17 19 23 29
825-
data = bytearray([1]) * n
826-
data[:2] = 0, 0
825+
data = bytearray((0, 1)) * (n // 2)
826+
data[:3] = 0, 0, 0
827827
limit = math.isqrt(n) + 1
828828
for p in compress(range(limit), data):
829-
data[p*p : n : p] = bytearray(len(range(p*p, n, p)))
830-
return iter_index(data, 1)
829+
data[p*p : n : p+p] = bytes(len(range(p*p, n, p+p)))
830+
data[2] = 1
831+
return iter_index(data, 1) if n > 2 else iter([])
831832

832833
def flatten(list_of_lists):
833834
"Flatten one level of nesting"

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/cpython/commit/3a639bbeace73d54f7e5431d3224c8c8223d81ae

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy