Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
vstinner merged 6 commits intopython:mainfromneonene:decstate
Sep 28, 2024
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
add a getter function
  • Loading branch information
@neonene
neonene committedSep 27, 2024
commit7a9fac1fa5521685d91d64205a3dfb1cdc6c8682
13 changes: 13 additions & 0 deletionsModules/_decimal/_decimal.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand DownExpand Up@@ -190,6 +191,7 @@ typedef struct PyDecContextObject {
PyObject *flags;
int capitals;
PyThreadState *tstate;
decimal_state *modstate;
} PyDecContextObject;

typedef struct {
Expand All@@ -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;
}


Py_LOCAL_INLINE(PyObject *)
incr_true(void)
Expand DownExpand Up@@ -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);
Expand DownExpand Up@@ -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},
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp