mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
bpo-45963: Make space for the InterpreterFrame of a generator in that generator. (GH-29891)
* Make generator, coroutine and async gen structs all the same size. * Store interpreter frame in generator (and coroutine). Reduces the number of allocations neeeded for a generator from two to one.
This commit is contained in:
parent
f34d181fa1
commit
299483c95d
7 changed files with 128 additions and 145 deletions
|
@ -43,18 +43,12 @@ _PyFrame_MakeAndSetFrameObject(InterpreterFrame *frame)
|
|||
return f;
|
||||
}
|
||||
|
||||
InterpreterFrame *
|
||||
_PyFrame_Copy(InterpreterFrame *frame)
|
||||
void
|
||||
_PyFrame_Copy(InterpreterFrame *src, InterpreterFrame *dest)
|
||||
{
|
||||
assert(frame->stacktop >= frame->f_code->co_nlocalsplus);
|
||||
Py_ssize_t size = ((char*)&frame->localsplus[frame->stacktop]) - (char *)frame;
|
||||
InterpreterFrame *copy = PyMem_Malloc(size);
|
||||
if (copy == NULL) {
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
}
|
||||
memcpy(copy, frame, size);
|
||||
return copy;
|
||||
assert(src->stacktop >= src->f_code->co_nlocalsplus);
|
||||
Py_ssize_t size = ((char*)&src->localsplus[src->stacktop]) - (char *)src;
|
||||
memcpy(dest, src, size);
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
@ -112,7 +106,7 @@ _PyFrame_Clear(InterpreterFrame * frame)
|
|||
}
|
||||
Py_DECREF(f);
|
||||
}
|
||||
assert(_PyFrame_GetStackPointer(frame) >= _PyFrame_Stackbase(frame));
|
||||
assert(frame->stacktop >= 0);
|
||||
for (int i = 0; i < frame->stacktop; i++) {
|
||||
Py_XDECREF(frame->localsplus[i]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue