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
b9d98d53
Kaydet (Commit)
b9d98d53
authored
Eki 02, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #24483: C implementation of functools.lru_cache() now calculates key's
hash only once.
üst
c9fda9b9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
6 deletions
+64
-6
dictobject.h
Include/dictobject.h
+4
-0
NEWS
Misc/NEWS
+3
-0
_functoolsmodule.c
Modules/_functoolsmodule.c
+20
-6
dictobject.c
Objects/dictobject.c
+37
-0
No files found.
Include/dictobject.h
Dosyayı görüntüle @
b9d98d53
...
...
@@ -72,6 +72,10 @@ PyAPI_FUNC(int) _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key,
PyObject
*
item
,
Py_hash_t
hash
);
#endif
PyAPI_FUNC
(
int
)
PyDict_DelItem
(
PyObject
*
mp
,
PyObject
*
key
);
#ifndef Py_LIMITED_API
PyAPI_FUNC
(
int
)
_PyDict_DelItem_KnownHash
(
PyObject
*
mp
,
PyObject
*
key
,
Py_hash_t
hash
);
#endif
PyAPI_FUNC
(
void
)
PyDict_Clear
(
PyObject
*
mp
);
PyAPI_FUNC
(
int
)
PyDict_Next
(
PyObject
*
mp
,
Py_ssize_t
*
pos
,
PyObject
**
key
,
PyObject
**
value
);
...
...
Misc/NEWS
Dosyayı görüntüle @
b9d98d53
...
...
@@ -32,6 +32,9 @@ Core and Builtins
Library
-------
-
Issue
#
24483
:
C
implementation
of
functools
.
lru_cache
()
now
calculates
key
's
hash only once.
- Issue #22958: Constructor and update method of weakref.WeakValueDictionary
now accept the self and the dict keyword arguments.
...
...
Modules/_functoolsmodule.c
Dosyayı görüntüle @
b9d98d53
...
...
@@ -601,6 +601,7 @@ struct lru_cache_object;
typedef
struct
lru_list_elem
{
PyObject_HEAD
struct
lru_list_elem
*
prev
,
*
next
;
/* borrowed links */
Py_hash_t
hash
;
PyObject
*
key
,
*
result
;
}
lru_list_elem
;
...
...
@@ -762,10 +763,14 @@ static PyObject *
infinite_lru_cache_wrapper
(
lru_cache_object
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
PyObject
*
result
;
Py_hash_t
hash
;
PyObject
*
key
=
lru_cache_make_key
(
args
,
kwds
,
self
->
typed
);
if
(
!
key
)
return
NULL
;
result
=
PyDict_GetItemWithError
(
self
->
cache
,
key
);
hash
=
PyObject_Hash
(
key
);
if
(
hash
==
-
1
)
return
NULL
;
result
=
_PyDict_GetItem_KnownHash
(
self
->
cache
,
key
,
hash
);
if
(
result
)
{
Py_INCREF
(
result
);
self
->
hits
++
;
...
...
@@ -781,7 +786,7 @@ infinite_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwd
Py_DECREF
(
key
);
return
NULL
;
}
if
(
PyDict_SetItem
(
self
->
cache
,
key
,
result
)
<
0
)
{
if
(
_PyDict_SetItem_KnownHash
(
self
->
cache
,
key
,
result
,
hash
)
<
0
)
{
Py_DECREF
(
result
);
Py_DECREF
(
key
);
return
NULL
;
...
...
@@ -813,11 +818,15 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
{
lru_list_elem
*
link
;
PyObject
*
key
,
*
result
;
Py_hash_t
hash
;
key
=
lru_cache_make_key
(
args
,
kwds
,
self
->
typed
);
if
(
!
key
)
return
NULL
;
link
=
(
lru_list_elem
*
)
PyDict_GetItemWithError
(
self
->
cache
,
key
);
hash
=
PyObject_Hash
(
key
);
if
(
hash
==
-
1
)
return
NULL
;
link
=
(
lru_list_elem
*
)
_PyDict_GetItem_KnownHash
(
self
->
cache
,
key
,
hash
);
if
(
link
)
{
lru_cache_extricate_link
(
link
);
lru_cache_append_link
(
self
,
link
);
...
...
@@ -845,7 +854,8 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
/* Remove it from the cache.
The cache dict holds one reference to the link,
and the linked list holds yet one reference to it. */
if
(
PyDict_DelItem
(
self
->
cache
,
link
->
key
)
<
0
)
{
if
(
_PyDict_DelItem_KnownHash
(
self
->
cache
,
link
->
key
,
link
->
hash
)
<
0
)
{
lru_cache_append_link
(
self
,
link
);
Py_DECREF
(
key
);
Py_DECREF
(
result
);
...
...
@@ -859,9 +869,11 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
oldkey
=
link
->
key
;
oldresult
=
link
->
result
;
link
->
hash
=
hash
;
link
->
key
=
key
;
link
->
result
=
result
;
if
(
PyDict_SetItem
(
self
->
cache
,
key
,
(
PyObject
*
)
link
)
<
0
)
{
if
(
_PyDict_SetItem_KnownHash
(
self
->
cache
,
key
,
(
PyObject
*
)
link
,
hash
)
<
0
)
{
Py_DECREF
(
link
);
Py_DECREF
(
oldkey
);
Py_DECREF
(
oldresult
);
...
...
@@ -881,10 +893,12 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
return
NULL
;
}
link
->
hash
=
hash
;
link
->
key
=
key
;
link
->
result
=
result
;
_PyObject_GC_TRACK
(
link
);
if
(
PyDict_SetItem
(
self
->
cache
,
key
,
(
PyObject
*
)
link
)
<
0
)
{
if
(
_PyDict_SetItem_KnownHash
(
self
->
cache
,
key
,
(
PyObject
*
)
link
,
hash
)
<
0
)
{
Py_DECREF
(
link
);
return
NULL
;
}
...
...
Objects/dictobject.c
Dosyayı görüntüle @
b9d98d53
...
...
@@ -1242,6 +1242,7 @@ _PyDict_SetItem_KnownHash(PyObject *op, PyObject *key, PyObject *value,
}
assert
(
key
);
assert
(
value
);
assert
(
hash
!=
-
1
);
mp
=
(
PyDictObject
*
)
op
;
/* insertdict() handles any resizing that might be necessary */
...
...
@@ -1290,6 +1291,42 @@ PyDict_DelItem(PyObject *op, PyObject *key)
return
0
;
}
int
_PyDict_DelItem_KnownHash
(
PyObject
*
op
,
PyObject
*
key
,
Py_hash_t
hash
)
{
PyDictObject
*
mp
;
PyDictKeyEntry
*
ep
;
PyObject
*
old_key
,
*
old_value
;
PyObject
**
value_addr
;
if
(
!
PyDict_Check
(
op
))
{
PyErr_BadInternalCall
();
return
-
1
;
}
assert
(
key
);
assert
(
hash
!=
-
1
);
mp
=
(
PyDictObject
*
)
op
;
ep
=
(
mp
->
ma_keys
->
dk_lookup
)(
mp
,
key
,
hash
,
&
value_addr
);
if
(
ep
==
NULL
)
return
-
1
;
if
(
*
value_addr
==
NULL
)
{
_PyErr_SetKeyError
(
key
);
return
-
1
;
}
old_value
=
*
value_addr
;
*
value_addr
=
NULL
;
mp
->
ma_used
--
;
if
(
!
_PyDict_HasSplitTable
(
mp
))
{
ENSURE_ALLOWS_DELETIONS
(
mp
);
old_key
=
ep
->
me_key
;
Py_INCREF
(
dummy
);
ep
->
me_key
=
dummy
;
Py_DECREF
(
old_key
);
}
Py_DECREF
(
old_value
);
return
0
;
}
void
PyDict_Clear
(
PyObject
*
op
)
{
...
...
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