From ffdf1c30ab6940a5efe6f33e61678021d9fd14b6 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 31 Jan 2019 15:03:38 -0800 Subject: Consistently move the misses update to just before the user function call (GH-11715) --- Modules/_functoolsmodule.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'Modules') diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 141210204c..d72aaff2b1 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -796,10 +796,12 @@ lru_cache_make_key(PyObject *args, PyObject *kwds, int typed) static PyObject * uncached_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds) { - PyObject *result = PyObject_Call(self->func, args, kwds); + PyObject *result; + + self->misses++; + result = PyObject_Call(self->func, args, kwds); if (!result) return NULL; - self->misses++; return result; } @@ -827,6 +829,7 @@ infinite_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwd Py_DECREF(key); return NULL; } + self->misses++; result = PyObject_Call(self->func, args, kwds); if (!result) { Py_DECREF(key); @@ -838,7 +841,6 @@ infinite_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwd return NULL; } Py_DECREF(key); - self->misses++; return result; } -- cgit v1.2.1