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
7e4c1683
Commit
7e4c1683
authored
Mar 18, 2011
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor optimization -- factor a constant expression out of the inner-loop.
parent
f84f3c3d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
3 deletions
+3
-3
Lib/functools.py
Lib/functools.py
+3
-3
No files found.
Lib/functools.py
View file @
7e4c1683
...
...
@@ -140,7 +140,7 @@ def lru_cache(maxsize=100):
tuple
=
tuple
,
sorted
=
sorted
,
len
=
len
,
KeyError
=
KeyError
):
hits
=
misses
=
0
kwd_mark
=
object
()
# separates positional and keyword args
kwd_mark
=
(
object
(),)
# separates positional and keyword args
lock
=
Lock
()
# needed because ordereddicts aren't threadsafe
if
maxsize
is
None
:
...
...
@@ -151,7 +151,7 @@ def lru_cache(maxsize=100):
nonlocal
hits
,
misses
key
=
args
if
kwds
:
key
+=
(
kwd_mark
,)
+
tuple
(
sorted
(
kwds
.
items
()))
key
+=
kwd_mark
+
tuple
(
sorted
(
kwds
.
items
()))
try
:
result
=
cache
[
key
]
hits
+=
1
...
...
@@ -170,7 +170,7 @@ def lru_cache(maxsize=100):
nonlocal
hits
,
misses
key
=
args
if
kwds
:
key
+=
(
kwd_mark
,)
+
tuple
(
sorted
(
kwds
.
items
()))
key
+=
kwd_mark
+
tuple
(
sorted
(
kwds
.
items
()))
try
:
with
lock
:
result
=
cache
[
key
]
...
...
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