Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
1ff50df8
Kaydet (Commit)
1ff50df8
authored
Mar 30, 2012
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Minor cleanup: add whitespace, add comments, bring function attribute updates together.
üst
0192ba33
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
5 deletions
+4
-5
functools.py
Lib/functools.py
+4
-5
No files found.
Lib/functools.py
Dosyayı görüntüle @
1ff50df8
...
...
@@ -161,6 +161,7 @@ def lru_cache(maxsize=100, typed=False):
See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used
"""
# Users should only access the lru_cache through its public API:
# cache_info, cache_clear, and f.__wrapped__
# The internals of the lru_cache are encapsulated for thread safety and
...
...
@@ -192,7 +193,6 @@ def lru_cache(maxsize=100, typed=False):
if
maxsize
==
0
:
@wraps
(
user_function
)
def
wrapper
(
*
args
,
**
kwds
):
# no caching, just do a statistics update after a successful call
nonlocal
misses
...
...
@@ -202,7 +202,6 @@ def lru_cache(maxsize=100, typed=False):
elif
maxsize
is
None
:
@wraps
(
user_function
)
def
wrapper
(
*
args
,
**
kwds
):
# simple caching without ordering or size limit
nonlocal
hits
,
misses
...
...
@@ -218,7 +217,6 @@ def lru_cache(maxsize=100, typed=False):
else
:
@wraps
(
user_function
)
def
wrapper
(
*
args
,
**
kwds
):
# size limited caching that tracks accesses by recency
nonlocal
hits
,
misses
...
...
@@ -238,11 +236,12 @@ def lru_cache(maxsize=100, typed=False):
return
result
result
=
user_function
(
*
args
,
**
kwds
)
with
lock
:
# put result in a new link at the front of the list
last
=
root
[
PREV
]
link
=
[
last
,
root
,
key
,
result
]
cache
[
key
]
=
last
[
NEXT
]
=
root
[
PREV
]
=
link
if
_len
(
cache
)
>
maxsize
:
# purge least recently used cache entry
# purge
the
least recently used cache entry
old_prev
,
old_next
,
old_key
,
old_result
=
root
[
NEXT
]
root
[
NEXT
]
=
old_next
old_next
[
PREV
]
=
root
...
...
@@ -265,6 +264,6 @@ def lru_cache(maxsize=100, typed=False):
wrapper
.
cache_info
=
cache_info
wrapper
.
cache_clear
=
cache_clear
return
wrapper
return
update_wrapper
(
wrapper
,
user_function
)
return
decorating_function
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