bpo-44222: Improve _removeHandlerRef() for a very long _handlerList (GH-26325)

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
This commit is contained in:
Yonatan Goldschmidt 2021-05-26 01:40:23 +03:00 committed by GitHub
parent add805f921
commit 156699bca0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View 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()