]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44222: Improve _removeHandlerRef() for a very long _handlerList (GH-26325)
authorYonatan Goldschmidt <yon.goldschmidt@gmail.com>
Tue, 25 May 2021 22:40:23 +0000 (01:40 +0300)
committerGitHub <noreply@github.com>
Tue, 25 May 2021 22:40:23 +0000 (15:40 -0700)
The list lookups become a big burden for very long lists.
This patch changes the "happy flow" path of 2 lookups into 1 lookup.

Automerge-Triggered-By: GH:vsajip
Lib/logging/__init__.py

index 555f598de7a9253a80192cae23a326e7e6ea069b..7865b71c8737b4fb1d3c5fbf9942802074617a5e 100644 (file)
@@ -845,8 +845,9 @@ def _removeHandlerRef(wr):
     if acquire and release and handlers:
         acquire()
         try:
-            if wr in handlers:
-                handlers.remove(wr)
+            handlers.remove(wr)
+        except ValueError:
+            pass
         finally:
             release()