8000 Clarify the comment about dictkeys_incref() and dictkeys_decref(). · python/cpython@5aabfd7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5aabfd7

Browse files
Clarify the comment about dictkeys_incref() and dictkeys_decref().
1 parent aab493a commit 5aabfd7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Objects/dictobject.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,12 @@ _PyDict_DebugMallocStats(FILE *out)
300300

301301
static void free_keys_object(PyInterpreterState *interp, PyDictKeysObject *keys);
302302

303-
/* We might consider modifying PyDictKeysObject so we could use
304-
Py_INCREF() instead of dictkeys_incref() (and likewise with
305-
Py_DECREF() and dictkeys_decref()). However, there doesn't
306-
seem to be enough benefit (performance or otherwise) to justify
307-
the change. */
303+
/* PyDictKeysObject has refcounts like PyObject does, so we have the
304+
following two functions to mirror what Py_INCREF() and Py_DECREF() do.
305+
(Keep in mind that PyDictKeysObject isn't actually a PyObject.)
306+
Likewise a PyDictKeysObject can be immortal (e.g. Py_EMPTY_KEYS),
307+
so we apply a naive version of what Py_INCREF() and Py_DECREF() do
308+
for immortal objects. */
308309

309310
static inline void
310311
dictkeys_incref(PyDictKeysObject *dk)

0 commit comments

Comments
 (0)
0