From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Sat, 15 Oct 2022 21:24:05 +0000 (-0700) Subject: [3.11] Improve speed. Reduce auxiliary memory to 16.6% of the main array. (GH-98294... X-Git-Tag: v3.11.1~278 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a2ae35dfa4605f3f6a1777ce136b3872dcb97a8e;p=thirdparty%2FPython%2Fcpython.git [3.11] Improve speed. Reduce auxiliary memory to 16.6% of the main array. (GH-98294) (GH-98303) --- diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 004dd19a7f3a..49fb8407890c 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -822,12 +822,13 @@ which incur interpreter overhead. def sieve(n): "Primes less than n" # sieve(30) --> 2 3 5 7 11 13 17 19 23 29 - data = bytearray([1]) * n - data[:2] = 0, 0 + data = bytearray((0, 1)) * (n // 2) + data[:3] = 0, 0, 0 limit = math.isqrt(n) + 1 for p in compress(range(limit), data): - data[p*p : n : p] = bytearray(len(range(p*p, n, p))) - return iter_index(data, 1) + data[p*p : n : p+p] = bytes(len(range(p*p, n, p+p))) + data[2] = 1 + return iter_index(data, 1) if n > 2 else iter([]) def flatten(list_of_lists): "Flatten one level of nesting"