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
0c9050c2
Kaydet (Commit)
0c9050c2
authored
Haz 04, 2012
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Separate key creation logic from the sequence class that memoizes its hash value.
üst
ca75b000
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
19 deletions
+24
-19
functools.py
Lib/functools.py
+24
-19
No files found.
Lib/functools.py
Dosyayı görüntüle @
0c9050c2
...
...
@@ -142,30 +142,35 @@ except ImportError:
_CacheInfo
=
namedtuple
(
"CacheInfo"
,
[
"hits"
,
"misses"
,
"maxsize"
,
"currsize"
])
class
_CacheKey
(
list
):
'Make a cache key from optionally typed positional and keyword arguments'
class
_HashedSeq
(
list
):
__slots__
=
'hashvalue'
def
__init__
(
self
,
args
,
kwds
,
typed
,
kwd_mark
=
(
object
(),),
sorted
=
sorted
,
tuple
=
tuple
,
type
=
type
,
hash
=
hash
):
key
=
args
if
kwds
:
sorted_items
=
sorted
(
kwds
.
items
())
key
+=
kwd_mark
for
item
in
sorted_items
:
key
+=
item
if
typed
:
key
+=
tuple
(
type
(
v
)
for
v
in
args
)
if
kwds
:
key
+=
tuple
(
type
(
v
)
for
k
,
v
in
sorted_items
)
self
[:]
=
key
self
.
hashvalue
=
hash
(
key
)
# so we only have to hash just once
def
__init__
(
self
,
tup
,
hash
=
hash
):
self
[:]
=
tup
self
.
hashvalue
=
hash
(
tup
)
def
__hash__
(
self
):
return
self
.
hashvalue
def
_make_key
(
args
,
kwds
,
typed
,
kwd_mark
=
(
object
(),),
fasttypes
=
{
int
,
str
,
frozenset
,
type
(
None
)},
sorted
=
sorted
,
tuple
=
tuple
,
type
=
type
,
len
=
len
):
'Make a cache key from optionally typed positional and keyword arguments'
key
=
args
if
kwds
:
sorted_items
=
sorted
(
kwds
.
items
())
key
+=
kwd_mark
for
item
in
sorted_items
:
key
+=
item
if
typed
:
key
+=
tuple
(
type
(
v
)
for
v
in
args
)
if
kwds
:
key
+=
tuple
(
type
(
v
)
for
k
,
v
in
sorted_items
)
elif
len
(
key
)
==
1
and
type
(
key
[
0
])
in
fasttypes
:
return
key
[
0
]
return
_HashedSeq
(
key
)
def
lru_cache
(
maxsize
=
128
,
typed
=
False
):
"""Least-recently-used cache decorator.
...
...
@@ -193,7 +198,7 @@ def lru_cache(maxsize=128, typed=False):
# Constants shared by all lru cache instances:
sentinel
=
object
()
# unique object used to signal cache misses
make_key
=
_
CacheK
ey
# build a key from the function arguments
make_key
=
_
make_k
ey
# build a key from the function arguments
PREV
,
NEXT
,
KEY
,
RESULT
=
0
,
1
,
2
,
3
# names for the link fields
def
decorating_function
(
user_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