Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
ffdf1c30
Commit
ffdf1c30
authored
Jan 31, 2019
by
Raymond Hettinger
Committed by
GitHub
Jan 31, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consistently move the misses update to just before the user function call (GH-11715)
parent
dcfcd146
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
6 deletions
+8
-6
Lib/functools.py
Lib/functools.py
+3
-3
Modules/_functoolsmodule.c
Modules/_functoolsmodule.c
+5
-3
No files found.
Lib/functools.py
View file @
ffdf1c30
...
...
@@ -541,10 +541,10 @@ def _lru_cache_wrapper(user_function, maxsize, typed, _CacheInfo):
if
maxsize
==
0
:
def
wrapper
(
*
args
,
**
kwds
):
# No caching -- just a statistics update
after a successful call
# No caching -- just a statistics update
nonlocal
misses
result
=
user_function
(
*
args
,
**
kwds
)
misses
+=
1
result
=
user_function
(
*
args
,
**
kwds
)
return
result
elif
maxsize
is
None
:
...
...
@@ -557,9 +557,9 @@ def _lru_cache_wrapper(user_function, maxsize, typed, _CacheInfo):
if
result
is
not
sentinel
:
hits
+=
1
return
result
misses
+=
1
result
=
user_function
(
*
args
,
**
kwds
)
cache
[
key
]
=
result
misses
+=
1
return
result
else
:
...
...
Modules/_functoolsmodule.c
View file @
ffdf1c30
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment