Skip to content

Commit 52f8cf0

Browse files
committed
Speed up frame local item collection
1 parent 2f064fb commit 52f8cf0

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Speed up frame local variable item collection by appending result pairs to the
2+
output list without an extra reference-count round-trip (using the internal
3+
reference-stealing list append helper).

Objects/frameobject.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "pycore_function.h" // _PyFunction_FromConstructor()
1010
#include "pycore_genobject.h" // _PyGen_GetGeneratorFromFrame()
1111
#include "pycore_interpframe.h" // _PyFrame_GetLocalsArray()
12+
#include "pycore_list.h" // _PyList_AppendTakeRef()
1213
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
1314
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
1415
#include "pycore_opcode_metadata.h" // _PyOpcode_Caches
@@ -636,9 +637,7 @@ framelocalsproxy_items(PyObject *self, PyObject *Py_UNUSED(ignored))
636637
goto error;
637638
}
638639

639-
int rc = PyList_Append(items, pair);
640-
Py_DECREF(pair);
641-
if (rc < 0) {
640+
if (_PyList_AppendTakeRef((PyListObject *)items, pair) < 0) {
642641
goto error;
643642
}
644643
}
@@ -655,9 +654,7 @@ framelocalsproxy_items(PyObject *self, PyObject *Py_UNUSED(ignored))
655654
goto error;
656655
}
657656

658-
int rc = PyList_Append(items, pair);
659-
Py_DECREF(pair);
660-
if (rc < 0) {
657+
if (_PyList_AppendTakeRef((PyListObject *)items, pair) < 0) {
661658
goto error;
662659
}
663660
}

0 commit comments

Comments
 (0)