mirror of
https://github.com/python/cpython.git
synced 2025-08-24 18:55:00 +00:00
gh-100146: Steal references from stack when building a list (#100147)
When executing the BUILD_LIST opcode, steal the references from the stack, in a manner similar to the BUILD_TUPLE opcode. Implement this by offloading the logic to a new private API, _PyList_FromArraySteal(), that works similarly to _PyTuple_FromArraySteal(). This way, instead of performing multiple stack pointer adjustments while the list is being initialized, the stack is adjusted only once and a fast memory copy operation is performed in one fell swoop.
This commit is contained in:
parent
b3722ca058
commit
e6d4440782
5 changed files with 31 additions and 10 deletions
|
@ -1390,13 +1390,10 @@ dummy_func(
|
|||
|
||||
// stack effect: (__array[oparg] -- __0)
|
||||
inst(BUILD_LIST) {
|
||||
PyObject *list = PyList_New(oparg);
|
||||
STACK_SHRINK(oparg);
|
||||
PyObject *list = _PyList_FromArraySteal(stack_pointer, oparg);
|
||||
if (list == NULL)
|
||||
goto error;
|
||||
while (--oparg >= 0) {
|
||||
PyObject *item = POP();
|
||||
PyList_SET_ITEM(list, oparg, item);
|
||||
}
|
||||
PUSH(list);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue