Skip to content

Commit 0ba2f5d

Browse files
committed
Use has_unique_reference
1 parent 902ce67 commit 0ba2f5d

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

Objects/dictobject.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5428,13 +5428,23 @@ dictiter_iternext_threadsafe(PyDictObject *d, PyObject *self,
54285428

54295429
#endif
54305430

5431+
static bool
5432+
has_unique_reference(PyObject *op)
5433+
{
5434+
#ifdef Py_GIL_DISABLED
5435+
return (_Py_IsOwnedByCurrentThread(op) &&
5436+
op->ob_ref_local == 1 &&
5437+
_Py_atomic_load_ssize_relaxed(&op->ob_ref_shared) == 0);
5438+
#else
5439+
return Py_REFCNT(op) == 1;
5440+
#endif
5441+
}
5442+
54315443
static bool
54325444
acquire_iter_result(PyObject *result)
54335445
{
54345446
#ifdef Py_GIL_DISABLED
5435-
if (_Py_IsOwnedByCurrentThread(result) &&
5436-
result->ob_ref_local == 1 &&
5437-
_Py_atomic_load_ssize_relaxed(&result->ob_ref_shared) == 0) {
5447+
if (has_unique_reference(result)) {
54385448
#else
54395449
if (Py_REFCNT(result) == 1) {
54405450
#endif
@@ -6647,18 +6657,6 @@ _PyObject_MakeDictFromInstanceAttributes(PyObject *obj, PyDictValues *values)
66476657
return make_dict_from_instance_attributes(interp, keys, values);
66486658
}
66496659

6650-
static bool
6651-
has_unique_reference(PyObject *op)
6652-
{
6653-
#ifdef Py_GIL_DISABLED
6654-
return (_Py_IsOwnedByCurrentThread(op) &&
6655-
op->ob_ref_local == 1 &&
6656-
_Py_atomic_load_ssize_relaxed(&op->ob_ref_shared) == 0);
6657-
#else
6658-
return Py_REFCNT(op) == 1;
6659-
#endif
6660-
}
6661-
66626660
// Return true if the dict was dematerialized, false otherwise.
66636661
bool
66646662
_PyObject_MakeInstanceAttributesFromDict(PyObject *obj, PyDictOrValues *dorv)

0 commit comments

Comments
 (0)