Skip to content

Commit 76646b0

Browse files
committed
gh-159437: Remove redundant tuple untracking guards
1 parent 25c2e1f commit 76646b0

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎Include/internal/pycore_tuple.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ extern "C" {
1111
#include "pycore_object.h" // _PyObject_GC_IS_TRACKED
1212
#include "pycore_structs.h" // _PyStackRef
1313

14-
/* Check whether an object is eligible for tuple untracking.
15-
* `op`: The live object to inspect.
16-
* Returns: True for an exact tracked tuple with no NULL or potentially tracked items.
14+
/* Check whether an exact tracked tuple is eligible for untracking.
15+
* `op`: A live exact tuple currently tracked by the GC.
16+
* Returns: True if the tuple has no NULL or potentially tracked items.
1717
*/
1818
extern bool _PyTuple_CanUntrack(PyObject *op);
1919
extern void _PyTuple_MaybeUntrack(PyObject *);

‎Objects/tupleobject.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ _PyTuple_CanUntrack(PyObject *op)
140140
PyTupleObject *t;
141141
Py_ssize_t i, n;
142142

143-
if (!PyTuple_CheckExact(op) || !_PyObject_GC_IS_TRACKED(op))
144-
return false;
143+
assert(PyTuple_CheckExact(op));
144+
assert(_PyObject_GC_IS_TRACKED(op));
145145
t = (PyTupleObject *) op;
146146
n = Py_SIZE(t);
147147
for (i = 0; i < n; i++) {
@@ -159,6 +159,9 @@ _PyTuple_CanUntrack(PyObject *op)
159159
void
160160
_PyTuple_MaybeUntrack(PyObject *op)
161161
{
162+
if (!PyTuple_CheckExact(op) || !_PyObject_GC_IS_TRACKED(op)) {
163+
return;
164+
}
162165
if (_PyTuple_CanUntrack(op)) {
163166
_PyObject_GC_UNTRACK(op);
164167
}

0 commit comments

Comments
 (0)