Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.4k
gh-124688: _decimal: Get a module state from ctx objects for performance#124691
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
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
7a9fac1 add a getter function
neonene818c24f add _dec_mpd_radix()
neonene00d2322 PyDecType_New, dec_alloc, dec_from_long
neoneneab5adad replace related get_module_state_by_def()
neonenea34f2d3 delete some spaces
neonenef7dd655 Update Modules/_decimal/_decimal.c
vstinnerFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
NextNext commit
add a getter function
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit7a9fac1fa5521685d91d64205a3dfb1cdc6c8682
There are no files selected for viewing
13 changes: 13 additions & 0 deletionsModules/_decimal/_decimal.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -123,6 +123,7 @@ get_module_state(PyObject *mod) | ||
| static struct PyModuleDef _decimal_module; | ||
| static PyType_Spec dec_spec; | ||
| static PyType_Spec context_spec; | ||
| static inline decimal_state * | ||
| get_module_state_by_def(PyTypeObject *tp) | ||
| @@ -190,6 +191,7 @@ typedef struct PyDecContextObject { | ||
| PyObject *flags; | ||
| int capitals; | ||
| PyThreadState *tstate; | ||
| decimal_state *modstate; | ||
| } PyDecContextObject; | ||
| typedef struct { | ||
| @@ -210,6 +212,15 @@ typedef struct { | ||
| #define CTX(v) (&((PyDecContextObject *)v)->ctx) | ||
| #define CtxCaps(v) (((PyDecContextObject *)v)->capitals) | ||
| static inline decimal_state * | ||
| get_module_state_from_ctx(PyObject *v) | ||
| { | ||
| assert(PyType_GetBaseByToken(Py_TYPE(v), &context_spec, NULL) == 1); | ||
| void *state = ((PyDecContextObject *)v)->modstate; | ||
| assert(state != NULL); | ||
| return (decimal_state *)state; | ||
vstinner marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| } | ||
| Py_LOCAL_INLINE(PyObject *) | ||
| incr_true(void) | ||
| @@ -1393,6 +1404,7 @@ context_new(PyTypeObject *type, | ||
| CtxCaps(self) = 1; | ||
| self->tstate = NULL; | ||
| self->modstate = state; | ||
| if (type == state->PyDecContext_Type) { | ||
| PyObject_GC_Track(self); | ||
| @@ -5736,6 +5748,7 @@ static PyMethodDef context_methods [] = | ||
| }; | ||
| static PyType_Slot context_slots[] = { | ||
| {Py_tp_token, Py_TP_USE_SPEC}, | ||
| {Py_tp_dealloc, context_dealloc}, | ||
| {Py_tp_traverse, context_traverse}, | ||
| {Py_tp_clear, context_clear}, | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.