diff options
author | mpage <mpage@meta.com> | 2024-12-19 21:03:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-19 21:03:14 (GMT) |
commit | 255762c09fe518757bb3e8ce1bb6e5d8eec9f466 (patch) | |
tree | 179d8f0893a0550d2f73359da6e20d4df05e01e2 /Python | |
parent | e163e8d4e1a9844b8615ef38b9917b887a377948 (diff) | |
download | cpython-255762c09fe518757bb3e8ce1bb6e5d8eec9f466.zip cpython-255762c09fe518757bb3e8ce1bb6e5d8eec9f466.tar.gz cpython-255762c09fe518757bb3e8ce1bb6e5d8eec9f466.tar.bz2 |
gh-127274: Defer nested methods (#128012)
Methods (functions defined in class scope) are likely to be cleaned
up by the GC anyway.
Add a new code flag, `CO_METHOD`, that is set for functions defined
in a class scope. Use that when deciding to defer functions.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/compile.c | 2 | ||||
-rw-r--r-- | Python/symtable.c | 7 |
2 files changed, 9 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c index cbfba7f..ef47083 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1289,6 +1289,8 @@ compute_code_flags(compiler *c) flags |= CO_VARKEYWORDS; if (ste->ste_has_docstring) flags |= CO_HAS_DOCSTRING; + if (ste->ste_method) + flags |= CO_METHOD; } if (ste->ste_coroutine && !ste->ste_generator) { diff --git a/Python/symtable.c b/Python/symtable.c index ebddb0b..49bd01b 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -138,6 +138,13 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block, ste->ste_has_docstring = 0; + ste->ste_method = 0; + if (st->st_cur != NULL && + st->st_cur->ste_type == ClassBlock && + block == FunctionBlock) { + ste->ste_method = 1; + } + ste->ste_symbols = PyDict_New(); ste->ste_varnames = PyList_New(0); ste->ste_children = PyList_New(0); |