]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-26544: Make platform.libc_ver() less slow (GH-10868)
authorVictor Stinner <vstinner@redhat.com>
Mon, 3 Dec 2018 15:49:24 +0000 (16:49 +0100)
committerGitHub <noreply@github.com>
Mon, 3 Dec 2018 15:49:24 +0000 (16:49 +0100)
Coarse benchmark on Fedora 29: 1.6 sec => 0.1 sec.

Co-Authored-By: Antoine Pitrou <solipsis@pitrou.net>
(cherry-picked from commit ba7c226095703f63c78b00e56f1db8d99ac3a54a)

Lib/platform.py

index 62a5476a8f4d3039e3a7c08452fc4bdc9c9e99b5..e04d87f258a745b3ac64d37461c77e1829cc99a4 100755 (executable)
@@ -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: