gh-91539: Small performance improvement of urrlib.request.getproxies_environment() (#108771)

Small performance improvement of getproxies_environment() when there are many environment variables. In a benchmark with 5k environment variables not related to proxies, and 5 specifying proxies, we get a 10% walltime improvement.
This commit is contained in:
Raphaël Marinier 2024-01-16 00:45:01 +01:00 committed by GitHub
parent 4f24b92aa0
commit 5094690efd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View file

@ -2490,7 +2490,7 @@ def getproxies_environment():
# select only environment variables which end in (after making lowercase) _proxy
proxies = {}
environment = []
for name in os.environ.keys():
for name in os.environ:
# fast screen underscore position before more expensive case-folding
if len(name) > 5 and name[-6] == "_" and name[-5:].lower() == "proxy":
value = os.environ[name]

View file

@ -0,0 +1 @@
Small (10 - 20%) and trivial performance improvement of :func:`urrlib.request.getproxies_environment`, typically useful when there are many environment variables to go over.