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
38d17e3d
Commit
38d17e3d
authored
Sep 02, 2010
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Speed-up cache updates
parent
ccb90e3c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
Lib/collections.py
Lib/collections.py
+13
-0
Lib/functools.py
Lib/functools.py
+1
-2
No files found.
Lib/collections.py
View file @
38d17e3d
...
@@ -161,6 +161,19 @@ class OrderedDict(dict, MutableMapping):
...
@@ -161,6 +161,19 @@ class OrderedDict(dict, MutableMapping):
def
__del__
(
self
):
def
__del__
(
self
):
self
.
clear
()
# eliminate cyclical references
self
.
clear
()
# eliminate cyclical references
def
_move_to_end
(
self
,
key
,
PREV
=
0
,
NEXT
=
1
):
'Fast version of self[key]=self.pop(key). Private method for internal use.'
link
=
self
.
__map
[
key
]
link_prev
=
link
[
PREV
]
link_next
=
link
[
NEXT
]
link_prev
[
NEXT
]
=
link_next
link_next
[
PREV
]
=
link_prev
root
=
self
.
__root
last
=
root
[
PREV
]
link
[
PREV
]
=
last
link
[
NEXT
]
=
root
last
[
NEXT
]
=
root
[
PREV
]
=
link
################################################################################
################################################################################
### namedtuple
### namedtuple
...
...
Lib/functools.py
View file @
38d17e3d
...
@@ -139,8 +139,7 @@ def lru_cache(maxsize=100):
...
@@ -139,8 +139,7 @@ def lru_cache(maxsize=100):
try
:
try
:
with
lock
:
with
lock
:
result
=
cache
[
key
]
result
=
cache
[
key
]
del
cache
[
key
]
cache
.
_move_to_end
(
key
)
# record recent use of this key
cache
[
key
]
=
result
# record recent use of this key
wrapper
.
hits
+=
1
wrapper
.
hits
+=
1
except
KeyError
:
except
KeyError
:
result
=
user_function
(
*
args
,
**
kwds
)
result
=
user_function
(
*
args
,
**
kwds
)
...
...
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