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
9f0ab9f5
Commit
9f0ab9f5
authored
Apr 29, 2012
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor out shared variables.
parent
678e7f3b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
Lib/functools.py
Lib/functools.py
+6
-4
No files found.
Lib/functools.py
View file @
9f0ab9f5
...
...
@@ -167,18 +167,20 @@ def lru_cache(maxsize=100, typed=False):
# The internals of the lru_cache are encapsulated for thread safety and
# to allow the implementation to change (including a possible C version).
# Constants shared by all lru cache instances:
kwd_mark
=
(
object
(),)
# separate positional and keyword args
sentinel
=
object
()
# unique object used to signal cache misses
_len
=
len
# localize the global len() function
PREV
,
NEXT
,
KEY
,
RESULT
=
0
,
1
,
2
,
3
# names for the link fields
def
decorating_function
(
user_function
):
cache
=
{}
hits
=
misses
=
0
kwd_mark
=
(
object
(),)
# separate positional and keyword args
cache_get
=
cache
.
get
# bound method to lookup a key or return None
sentinel
=
object
()
# unique object used with cache_get
_len
=
len
# localize the global len() function
lock
=
Lock
()
# because linkedlist updates aren't threadsafe
root
=
[]
# root of the circular doubly linked list
root
[:]
=
[
root
,
root
,
None
,
None
]
# initialize by pointing to self
PREV
,
NEXT
,
KEY
,
RESULT
=
0
,
1
,
2
,
3
# names for the link fields
def
make_key
(
args
,
kwds
,
typed
,
tuple
=
tuple
,
sorted
=
sorted
,
type
=
type
):
# build a cache key from positional and keyword args
...
...
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