diff options
author | Mark Shannon <mark@hotpy.org> | 2021-08-25 12:44:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-25 12:44:20 (GMT) |
commit | f9242d50b18572ef0d584a1c815ed08d1a38e4f4 (patch) | |
tree | 0c7c137c701b1dd69f89227dee85aaee95ff5dfb /Python/pystate.c | |
parent | 214c2e5d916d3ce5e7b1db800210b93001850bbb (diff) | |
download | cpython-f9242d50b18572ef0d584a1c815ed08d1a38e4f4.zip cpython-f9242d50b18572ef0d584a1c815ed08d1a38e4f4.tar.gz cpython-f9242d50b18572ef0d584a1c815ed08d1a38e4f4.tar.bz2 |
bpo-44990: Change layout of evaluation frames. "Layout B" (GH-27933)
Places the locals between the specials and stack. This is the more "natural" layout for a C struct, makes the code simpler and gives a slight speedup (~1%)
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index 6a15b54..4527214 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -2045,21 +2045,21 @@ _PyThreadState_PushFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObjec size_t size = nlocalsplus + code->co_stacksize + FRAME_SPECIALS_SIZE; assert(size < INT_MAX/sizeof(PyObject *)); - PyObject **localsarray = tstate->datastack_top; - PyObject **top = localsarray + size; + PyObject **base = tstate->datastack_top; + PyObject **top = base + size; if (top >= tstate->datastack_limit) { - localsarray = push_chunk(tstate, (int)size); - if (localsarray == NULL) { + base = push_chunk(tstate, (int)size); + if (base == NULL) { return NULL; } } else { tstate->datastack_top = top; } - InterpreterFrame * frame = (InterpreterFrame *)(localsarray + nlocalsplus); + InterpreterFrame *frame = (InterpreterFrame *)base; _PyFrame_InitializeSpecials(frame, con, locals, nlocalsplus); for (int i=0; i < nlocalsplus; i++) { - localsarray[i] = NULL; + frame->localsplus[i] = NULL; } return frame; } @@ -2067,8 +2067,8 @@ _PyThreadState_PushFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObjec void _PyThreadState_PopFrame(PyThreadState *tstate, InterpreterFrame * frame) { - PyObject **locals = _PyFrame_GetLocalsArray(frame); - if (locals == &tstate->datastack_chunk->data[0]) { + PyObject **base = (PyObject **)frame; + if (base == &tstate->datastack_chunk->data[0]) { _PyStackChunk *chunk = tstate->datastack_chunk; _PyStackChunk *previous = chunk->previous; tstate->datastack_top = &previous->data[previous->top]; @@ -2077,8 +2077,8 @@ _PyThreadState_PopFrame(PyThreadState *tstate, InterpreterFrame * frame) tstate->datastack_limit = (PyObject **)(((char *)previous) + previous->size); } else { - assert(tstate->datastack_top >= locals); - tstate->datastack_top = locals; + assert(tstate->datastack_top >= base); + tstate->datastack_top = base; } } |