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
2dda72a2
Kaydet (Commit)
2dda72a2
authored
Şub 09, 2019
tarafından
Raymond Hettinger
Kaydeden (comit)
Miss Islington (bot)
Şub 09, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
lru_cache: Add more comments. Fix comment typos. Clarify a comment. (GH-11795)
üst
7ab3d157
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
4 deletions
+25
-4
_functoolsmodule.c
Modules/_functoolsmodule.c
+25
-4
No files found.
Modules/_functoolsmodule.c
Dosyayı görüntüle @
2dda72a2
...
...
@@ -661,6 +661,26 @@ sequence is empty.");
/* lru_cache object **********************************************************/
/* There are four principal algorithmic differences from the pure python version:
1). The C version relies on the GIL instead of having its own reentrant lock.
2). The prev/next link fields use borrowed references.
3). For a full cache, the pure python version rotates the location of the
root entry so that it never has to move individual links and it can
limit updates to just the key and result fields. However, in the C
version, links are temporarily removed while the cache dict updates are
occurring. Afterwards, they are appended or prepended back into the
doubly-linked lists.
4) In the Python version, the _HashSeq class is used to prevent __hash__
from being called more than once. In the C version, the "known hash"
variants of dictionary calls as used to the same effect.
*/
/* this object is used delimit args and keywords in the cache keys */
static
PyObject
*
kwd_mark
=
NULL
;
...
...
@@ -1009,14 +1029,15 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
link
=
self
->
root
.
next
;
lru_cache_extract_link
(
link
);
/* Remove it from the cache.
The cache dict holds one reference to the link,
and the linked list holds yet one reference to it. */
The cache dict holds one reference to the link.
We created one other reference when the link was created.
The linked list only has borrowed references. */
popresult
=
_PyDict_Pop_KnownHash
(
self
->
cache
,
link
->
key
,
link
->
hash
,
Py_None
);
if
(
popresult
==
Py_None
)
{
/* Getting here means that the user function call or another
thread has already removed the old key from the dictionary.
This link is now an orpan. Since we don't want to leave the
This link is now an orp
h
an. Since we don't want to leave the
cache in an inconsistent state, we don't restore the link. */
Py_DECREF
(
popresult
);
Py_DECREF
(
link
);
...
...
@@ -1048,7 +1069,7 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
prev and next fields set to valid values. We have to wait
for successful insertion in the cache dict before adding the
link to the linked list. Otherwise, the potentially reentrant
__eq__ call could cause the then ophan link to be visited. */
__eq__ call could cause the then o
r
phan link to be visited. */
if
(
_PyDict_SetItem_KnownHash
(
self
->
cache
,
key
,
(
PyObject
*
)
link
,
hash
)
<
0
)
{
/* Somehow the cache dict update failed. We no longer can
...
...
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