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
2ddc7f6d
Unverified
Kaydet (Commit)
2ddc7f6d
authored
Mar 18, 2019
tarafından
Inada Naoki
Kaydeden (comit)
GitHub
Mar 18, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-30040: optimize inserting into empty dict (GH-12307)
üst
09a9f179
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
2 deletions
+49
-2
dictobject.c
Objects/dictobject.c
+49
-2
No files found.
Objects/dictobject.c
Dosyayı görüntüle @
2ddc7f6d
...
...
@@ -1102,6 +1102,41 @@ Fail:
return
-
1
;
}
// Same to insertdict but specialized for ma_keys = Py_EMPTY_KEYS.
static
int
insert_to_emptydict
(
PyDictObject
*
mp
,
PyObject
*
key
,
Py_hash_t
hash
,
PyObject
*
value
)
{
assert
(
mp
->
ma_keys
==
Py_EMPTY_KEYS
);
PyDictKeysObject
*
newkeys
=
new_keys_object
(
PyDict_MINSIZE
);
if
(
newkeys
==
NULL
)
{
return
-
1
;
}
if
(
!
PyUnicode_CheckExact
(
key
))
{
newkeys
->
dk_lookup
=
lookdict
;
}
dictkeys_decref
(
Py_EMPTY_KEYS
);
mp
->
ma_keys
=
newkeys
;
mp
->
ma_values
=
NULL
;
Py_INCREF
(
key
);
Py_INCREF
(
value
);
MAINTAIN_TRACKING
(
mp
,
key
,
value
);
size_t
hashpos
=
(
size_t
)
hash
&
(
PyDict_MINSIZE
-
1
);
PyDictKeyEntry
*
ep
=
&
DK_ENTRIES
(
mp
->
ma_keys
)[
0
];
dictkeys_set_index
(
mp
->
ma_keys
,
hashpos
,
0
);
ep
->
me_key
=
key
;
ep
->
me_hash
=
hash
;
ep
->
me_value
=
value
;
mp
->
ma_used
++
;
mp
->
ma_version_tag
=
DICT_NEXT_VERSION
();
mp
->
ma_keys
->
dk_usable
--
;
mp
->
ma_keys
->
dk_nentries
++
;
return
0
;
}
/*
Internal routine used by dictresize() to build a hashtable of entries.
*/
...
...
@@ -1274,7 +1309,7 @@ _PyDict_NewPresized(Py_ssize_t minused)
Py_ssize_t
newsize
;
PyDictKeysObject
*
new_keys
;
if
(
minused
==
0
)
{
if
(
minused
<=
USABLE_FRACTION
(
PyDict_MINSIZE
)
)
{
return
PyDict_New
();
}
/* There are no strict guarantee that returned dict can contain minused
...
...
@@ -1286,7 +1321,7 @@ _PyDict_NewPresized(Py_ssize_t minused)
}
else
{
Py_ssize_t
minsize
=
ESTIMATE_SIZE
(
minused
);
newsize
=
PyDict_MINSIZE
;
newsize
=
PyDict_MINSIZE
*
2
;
while
(
newsize
<
minsize
)
{
newsize
<<=
1
;
}
...
...
@@ -1495,6 +1530,9 @@ PyDict_SetItem(PyObject *op, PyObject *key, PyObject *value)
return
-
1
;
}
if
(
mp
->
ma_keys
==
Py_EMPTY_KEYS
)
{
return
insert_to_emptydict
(
mp
,
key
,
hash
,
value
);
}
/* insertdict() handles any resizing that might be necessary */
return
insertdict
(
mp
,
key
,
hash
,
value
);
}
...
...
@@ -1514,6 +1552,9 @@ _PyDict_SetItem_KnownHash(PyObject *op, PyObject *key, PyObject *value,
assert
(
hash
!=
-
1
);
mp
=
(
PyDictObject
*
)
op
;
if
(
mp
->
ma_keys
==
Py_EMPTY_KEYS
)
{
return
insert_to_emptydict
(
mp
,
key
,
hash
,
value
);
}
/* insertdict() handles any resizing that might be necessary */
return
insertdict
(
mp
,
key
,
hash
,
value
);
}
...
...
@@ -2844,6 +2885,12 @@ PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *defaultobj)
if
(
hash
==
-
1
)
return
NULL
;
}
if
(
mp
->
ma_keys
==
Py_EMPTY_KEYS
)
{
if
(
insert_to_emptydict
(
mp
,
key
,
hash
,
defaultobj
)
<
0
)
{
return
NULL
;
}
return
defaultobj
;
}
if
(
mp
->
ma_values
!=
NULL
&&
!
PyUnicode_CheckExact
(
key
))
{
if
(
insertion_resize
(
mp
)
<
0
)
...
...
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