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
832eddea
Kaydet (Commit)
832eddea
authored
Şub 17, 2013
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Eliminate unnecessary variable.
üst
5df9f825
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
10 deletions
+7
-10
functools.py
Lib/functools.py
+7
-10
No files found.
Lib/functools.py
Dosyayı görüntüle @
832eddea
...
...
@@ -228,9 +228,8 @@ def lru_cache(maxsize=128, typed=False):
PREV
,
NEXT
,
KEY
,
RESULT
=
0
,
1
,
2
,
3
# names for the link fields
def
decorating_function
(
user_function
):
cache
=
{}
hits
=
misses
=
currsize
=
0
hits
=
misses
=
0
full
=
False
cache_get
=
cache
.
get
# bound method to lookup a key or return None
lock
=
Lock
()
# because linkedlist updates aren't threadsafe
...
...
@@ -250,7 +249,7 @@ def lru_cache(maxsize=128, typed=False):
def
wrapper
(
*
args
,
**
kwds
):
# simple caching without ordering or size limit
nonlocal
hits
,
misses
,
currsize
nonlocal
hits
,
misses
key
=
make_key
(
args
,
kwds
,
typed
)
result
=
cache_get
(
key
,
sentinel
)
if
result
is
not
sentinel
:
...
...
@@ -259,14 +258,13 @@ def lru_cache(maxsize=128, typed=False):
result
=
user_function
(
*
args
,
**
kwds
)
cache
[
key
]
=
result
misses
+=
1
currsize
+=
1
return
result
else
:
def
wrapper
(
*
args
,
**
kwds
):
# size limited caching that tracks accesses by recency
nonlocal
root
,
hits
,
misses
,
currsize
,
full
nonlocal
root
,
hits
,
misses
,
full
key
=
make_key
(
args
,
kwds
,
typed
)
with
lock
:
link
=
cache_get
(
key
)
...
...
@@ -303,23 +301,22 @@ def lru_cache(maxsize=128, typed=False):
last
=
root
[
PREV
]
link
=
[
last
,
root
,
key
,
result
]
cache
[
key
]
=
last
[
NEXT
]
=
root
[
PREV
]
=
link
currsize
+=
1
full
=
(
currsize
==
maxsize
)
full
=
(
len
(
cache
)
==
maxsize
)
misses
+=
1
return
result
def
cache_info
():
"""Report cache statistics"""
with
lock
:
return
_CacheInfo
(
hits
,
misses
,
maxsize
,
currsize
)
return
_CacheInfo
(
hits
,
misses
,
maxsize
,
len
(
cache
)
)
def
cache_clear
():
"""Clear the cache and cache statistics"""
nonlocal
hits
,
misses
,
currsize
,
full
nonlocal
hits
,
misses
,
full
with
lock
:
cache
.
clear
()
root
[:]
=
[
root
,
root
,
None
,
None
]
hits
=
misses
=
currsize
=
0
hits
=
misses
=
0
full
=
False
wrapper
.
cache_info
=
cache_info
...
...
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