From: Victor Stinner Date: Mon, 3 Dec 2018 15:49:24 +0000 (+0100) Subject: bpo-26544: Make platform.libc_ver() less slow (GH-10868) X-Git-Tag: v2.7.16rc1~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8687bd86e6f138ef0699a1e9f3f9555765949b51;p=thirdparty%2FPython%2Fcpython.git bpo-26544: Make platform.libc_ver() less slow (GH-10868) Coarse benchmark on Fedora 29: 1.6 sec => 0.1 sec. Co-Authored-By: Antoine Pitrou (cherry-picked from commit ba7c226095703f63c78b00e56f1db8d99ac3a54a) --- diff --git a/Lib/platform.py b/Lib/platform.py index 62a5476a8f4d..e04d87f258a7 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -194,7 +194,10 @@ def libc_ver(executable=sys.executable,lib='',version='', chunksize=2048): binary = f.read(chunksize) pos = 0 while pos < len(binary): - m = _libc_search.search(binary,pos) + if 'libc' in binary or 'GLIBC' in binary: + m = _libc_search.search(binary, pos) + else: + m = None if not m or m.end() == len(binary): chunk = f.read(chunksize) if chunk: