Skip to content

Commit 5a03e52

Browse files
committed
Avoid decrefs by moving state lookup earlier in the function
1 parent a1e622e commit 5a03e52

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

Modules/_functoolsmodule.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,11 @@ lru_cache_new(PyTypeObject *type, PyObject *args, PyObject *kw)
11591159
return NULL;
11601160
}
11611161

1162+
state = get_functools_state_by_type(type);
1163+
if (state == NULL) {
1164+
return NULL;
1165+
}
1166+
11621167
/* select the caching function, and make/inc maxsize_O */
11631168
if (maxsize_O == Py_None) {
11641169
wrapper = infinite_lru_cache_wrapper;
@@ -1189,13 +1194,6 @@ lru_cache_new(PyTypeObject *type, PyObject *args, PyObject *kw)
11891194
return NULL;
11901195
}
11911196

1192-
state = get_functools_state_by_type(Py_TYPE(obj));
1193-
if (state == NULL) {
1194-
Py_DECREF(cachedict);
1195-
Py_DECREF(obj);
1196-
return NULL;
1197-
}
1198-
11991197
obj->root.prev = &obj->root;
12001198
obj->root.next = &obj->root;
12011199
obj->wrapper = wrapper;

0 commit comments

Comments
 (0)