summaryrefslogtreecommitdiff
path: root/Objects/codeobject.c
diff options
context:
space:
mode:
authorItamar Ostricher <itamarost@gmail.com>2022-12-14 11:14:16 -0800
committerGitHub <noreply@github.com>2022-12-14 19:14:16 +0000
commitae83c782155ffe86830c3255e338f366e331ad30 (patch)
tree353db1dc5287520c07b951467461deb8a10a84c4 /Objects/codeobject.c
parentaa8591e9ca9a3e55e96a03c17fa9d3902f0674dc (diff)
downloadcpython-git-ae83c782155ffe86830c3255e338f366e331ad30.tar.gz
GH-100000: Cleanup and polish various watchers code (GH-99998)
* Initialize `type_watchers` array to `NULL`s * Optimize code watchers notification * Optimize func watchers notification
Diffstat (limited to 'Objects/codeobject.c')
-rw-r--r--Objects/codeobject.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index f455cc603a..1e5a92270b 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -15,14 +15,21 @@ static void
notify_code_watchers(PyCodeEvent event, PyCodeObject *co)
{
PyInterpreterState *interp = _PyInterpreterState_GET();
- if (interp->active_code_watchers) {
- assert(interp->_initialized);
- for (int i = 0; i < CODE_MAX_WATCHERS; i++) {
+ assert(interp->_initialized);
+ uint8_t bits = interp->active_code_watchers;
+ int i = 0;
+ while (bits) {
+ assert(i < CODE_MAX_WATCHERS);
+ if (bits & 1) {
PyCode_WatchCallback cb = interp->code_watchers[i];
- if ((cb != NULL) && (cb(event, co) < 0)) {
+ // callback must be non-null if the watcher bit is set
+ assert(cb != NULL);
+ if (cb(event, co) < 0) {
PyErr_WriteUnraisable((PyObject *) co);
}
}
+ i++;
+ bits >>= 1;
}
}