Skip to content

Commit 6d7cdaf

Browse files
author
Erlend E. Aasland
committed
Address review
1 parent 8ef6e98 commit 6d7cdaf

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

Modules/_functoolsmodule.c

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -762,45 +762,25 @@ typedef struct lru_list_elem {
762762
PyObject *key, *result;
763763
} lru_list_elem;
764764

765-
static int
766-
lru_list_elem_clear(lru_list_elem *link)
767-
{
768-
Py_CLEAR(link->key);
769-
Py_CLEAR(link->result);
770-
return 0;
771-
}
772-
773-
static int
774-
lru_list_elem_traverse(lru_list_elem *link, visitproc visit, void *arg)
775-
{
776-
Py_VISIT(link->key);
777-
Py_VISIT(link->result);
778-
Py_VISIT(Py_TYPE(link));
779-
return 0;
780-
}
781-
782765
static void
783766
lru_list_elem_dealloc(lru_list_elem *link)
784767
{
785768
PyTypeObject *tp = Py_TYPE(link);
786-
PyObject_GC_UnTrack(link);
787-
(void)lru_list_elem_clear(link);
788-
PyObject_GC_Del(link);
769+
Py_CLEAR(link->key);
770+
Py_CLEAR(link->result);
771+
tp->tp_free(link);
789772
Py_DECREF(tp);
790773
}
791774

792775
static PyType_Slot lru_list_elem_type_slots[] = {
793776
{Py_tp_dealloc, lru_list_elem_dealloc},
794-
{Py_tp_traverse, lru_list_elem_traverse},
795-
{Py_tp_clear, lru_list_elem_clear},
796777
{0, 0}
797778
};
798779

799780
static PyType_Spec lru_list_elem_type_spec = {
800781
.name = "functools._lru_list_elem",
801782
.basicsize = sizeof(lru_list_elem),
802-
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
803-
Py_TPFLAGS_HAVE_GC),
783+
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
804784
.slots = lru_list_elem_type_slots
805785
};
806786

@@ -1065,8 +1045,8 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
10651045
self->root.next == &self->root)
10661046
{
10671047
/* Cache is not full, so put the result in a new link */
1068-
link = (lru_list_elem *)PyObject_GC_New(lru_list_elem,
1069-
self->lru_list_elem_type);
1048+
link = (lru_list_elem *)PyObject_New(lru_list_elem,
1049+
self->lru_list_elem_type);
10701050
if (link == NULL) {
10711051
Py_DECREF(key);
10721052
Py_DECREF(result);
@@ -1076,7 +1056,6 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
10761056
link->hash = hash;
10771057
link->key = key;
10781058
link->result = result;
1079-
PyObject_GC_Track(link);
10801059
/* What is really needed here is a SetItem variant with a "no clobber"
10811060
option. If the __eq__ call triggers a reentrant call that adds
10821061
this same key, then this setitem call will update the cache dict
@@ -1365,7 +1344,8 @@ lru_cache_tp_traverse(lru_cache_object *self, visitproc visit, void *arg)
13651344
lru_list_elem *link = self->root.next;
13661345
while (link != &self->root) {
13671346
lru_list_elem *next = link->next;
1368-
Py_VISIT(link);
1347+
Py_VISIT(link->key);
1348+
Py_VISIT(link->result);
13691349
link = next;
13701350
}
13711351
Py_VISIT(self->func);

0 commit comments

Comments
 (0)