Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
[3.11] gh-93382: Cache result ofPyCode_GetCode in codeobject (GH-93383)#93493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
13642ce0f9511f56b017d5af4e76be1baadc979855887120fb34659cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -88,6 +88,7 @@ typedef uint16_t _Py_CODEUNIT; | ||
| PyObject *co_qualname; /* unicode (qualname, for reference) */ \ | ||
| PyObject *co_linetable; /* bytes object that holds location info */ \ | ||
| PyObject *co_weakreflist; /* to support weakrefs to code objects */ \ | ||
| void *_co_code; /* cached co_code object/attribute */ \ | ||
Fidget-Spinner marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| /* Scratch space for extra data relating to the code object. \ | ||
| Type is a void* to keep the format private in codeobject.c to force \ | ||
| people to go through the proper APIs. */ \ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Speed up the:c:func:`PyCode_GetCode` function which also improves accessing the:attr:`~types.CodeType.co_code` attribute in Python. | ||
Fidget-Spinner marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -334,6 +334,7 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con) | ||
| /* not set */ | ||
| co->co_weakreflist = NULL; | ||
| co->co_extra = NULL; | ||
| co->_co_code = NULL; | ||
| co->co_warmup = QUICKENING_INITIAL_WARMUP_VALUE; | ||
| memcpy(_PyCode_CODE(co), PyBytes_AS_STRING(con->code), | ||
| @@ -1367,12 +1368,17 @@ deopt_code(_Py_CODEUNIT *instructions, Py_ssize_t len) | ||
| PyObject * | ||
| _PyCode_GetCode(PyCodeObject *co) | ||
| { | ||
| if (co->_co_code != NULL) { | ||
| return Py_NewRef(co->_co_code); | ||
| } | ||
| PyObject *code = PyBytes_FromStringAndSize((const char *)_PyCode_CODE(co), | ||
| _PyCode_NBYTES(co)); | ||
| if (code == NULL) { | ||
| return NULL; | ||
| } | ||
| deopt_code((_Py_CODEUNIT *)PyBytes_AS_STRING(code), Py_SIZE(co)); | ||
| assert(co->_co_code == NULL); | ||
Fidget-Spinner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| co->_co_code = (void *)Py_NewRef(code); | ||
| return code; | ||
| } | ||
| @@ -1531,6 +1537,7 @@ code_dealloc(PyCodeObject *co) | ||
| Py_XDECREF(co->co_qualname); | ||
| Py_XDECREF(co->co_linetable); | ||
| Py_XDECREF(co->co_exceptiontable); | ||
| Py_XDECREF(co->_co_code); | ||
| if (co->co_weakreflist != NULL) { | ||
| PyObject_ClearWeakRefs((PyObject*)co); | ||
| } | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.