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
93f26f79
Kaydet (Commit)
93f26f79
authored
Kas 02, 2016
tarafından
INADA Naoki
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #28583: PyDict_SetDefault didn't combine split table when needed.
Patch by Xiang Zhang.
üst
8567e58a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
15 deletions
+65
-15
test_dict.py
Lib/test/test_dict.py
+17
-0
NEWS
Misc/NEWS
+3
-0
dictobject.c
Objects/dictobject.c
+45
-15
No files found.
Lib/test/test_dict.py
Dosyayı görüntüle @
93f26f79
...
...
@@ -851,6 +851,23 @@ class DictTest(unittest.TestCase):
return
dicts
@support.cpython_only
def
test_splittable_setdefault
(
self
):
"""split table must be combined when setdefault()
breaks insertion order"""
a
,
b
=
self
.
make_shared_key_dict
(
2
)
a
[
'a'
]
=
1
size_a
=
sys
.
getsizeof
(
a
)
a
[
'b'
]
=
2
b
.
setdefault
(
'b'
,
2
)
size_b
=
sys
.
getsizeof
(
b
)
b
[
'a'
]
=
1
self
.
assertGreater
(
size_b
,
size_a
)
self
.
assertEqual
(
list
(
a
),
[
'x'
,
'y'
,
'z'
,
'a'
,
'b'
])
self
.
assertEqual
(
list
(
b
),
[
'x'
,
'y'
,
'z'
,
'b'
,
'a'
])
@support.cpython_only
def
test_splittable_del
(
self
):
"""split table must be combined when del d[k]"""
...
...
Misc/NEWS
Dosyayı görüntüle @
93f26f79
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.6.0 beta 4
Core and Builtins
-----------------
- Issue #28583: PyDict_SetDefault didn'
t
combine
split
table
when
needed
.
Patch
by
Xiang
Zhang
.
Library
-------
...
...
Objects/dictobject.c
Dosyayı görüntüle @
93f26f79
...
...
@@ -2757,58 +2757,88 @@ PyObject *
PyDict_SetDefault
(
PyObject
*
d
,
PyObject
*
key
,
PyObject
*
defaultobj
)
{
PyDictObject
*
mp
=
(
PyDictObject
*
)
d
;
PyObject
*
val
=
NULL
;
PyObject
*
val
ue
;
Py_hash_t
hash
;
Py_ssize_t
hashpos
,
ix
;
PyDictKeyEntry
*
ep
;
PyObject
**
value_addr
;
if
(
!
PyDict_Check
(
d
))
{
PyErr_BadInternalCall
();
return
NULL
;
}
if
(
!
PyUnicode_CheckExact
(
key
)
||
(
hash
=
((
PyASCIIObject
*
)
key
)
->
hash
)
==
-
1
)
{
hash
=
PyObject_Hash
(
key
);
if
(
hash
==
-
1
)
return
NULL
;
}
if
(
mp
->
ma_values
!=
NULL
&&
!
PyUnicode_CheckExact
(
key
))
{
if
(
insertion_resize
(
mp
)
<
0
)
return
NULL
;
}
ix
=
(
mp
->
ma_keys
->
dk_lookup
)(
mp
,
key
,
hash
,
&
value_addr
,
&
hashpos
);
if
(
ix
==
DKIX_ERROR
)
return
NULL
;
if
(
ix
==
DKIX_EMPTY
||
*
value_addr
==
NULL
)
{
val
=
defaultobj
;
if
(
_PyDict_HasSplitTable
(
mp
)
&&
((
ix
>=
0
&&
*
value_addr
==
NULL
&&
mp
->
ma_used
!=
ix
)
||
(
ix
==
DKIX_EMPTY
&&
mp
->
ma_used
!=
mp
->
ma_keys
->
dk_nentries
)))
{
if
(
insertion_resize
(
mp
)
<
0
)
{
return
NULL
;
}
find_empty_slot
(
mp
,
key
,
hash
,
&
value_addr
,
&
hashpos
);
ix
=
DKIX_EMPTY
;
}
if
(
ix
==
DKIX_EMPTY
)
{
PyDictKeyEntry
*
ep
,
*
ep0
;
value
=
defaultobj
;
if
(
mp
->
ma_keys
->
dk_usable
<=
0
)
{
/* Need to resize. */
if
(
insertion_resize
(
mp
)
<
0
)
{
return
NULL
;
}
find_empty_slot
(
mp
,
key
,
hash
,
&
value_addr
,
&
hashpos
);
}
ix
=
mp
->
ma_keys
->
dk_nentries
;
Py_INCREF
(
defaultobj
);
ep0
=
DK_ENTRIES
(
mp
->
ma_keys
);
ep
=
&
ep0
[
mp
->
ma_keys
->
dk_nentries
];
dk_set_index
(
mp
->
ma_keys
,
hashpos
,
mp
->
ma_keys
->
dk_nentries
);
Py_INCREF
(
key
);
MAINTAIN_TRACKING
(
mp
,
key
,
defaultobj
);
dk_set_index
(
mp
->
ma_keys
,
hashpos
,
ix
);
ep
=
&
DK_ENTRIES
(
mp
->
ma_keys
)[
ix
];
Py_INCREF
(
value
);
MAINTAIN_TRACKING
(
mp
,
key
,
value
);
ep
->
me_key
=
key
;
ep
->
me_hash
=
hash
;
if
(
mp
->
ma_values
)
{
mp
->
ma_values
[
ix
]
=
val
;
assert
(
mp
->
ma_values
[
mp
->
ma_keys
->
dk_nentries
]
==
NULL
);
mp
->
ma_values
[
mp
->
ma_keys
->
dk_nentries
]
=
value
;
}
else
{
ep
->
me_value
=
val
;
ep
->
me_value
=
val
ue
;
}
mp
->
ma_used
++
;
mp
->
ma_version_tag
=
DICT_NEXT_VERSION
();
mp
->
ma_keys
->
dk_usable
--
;
mp
->
ma_keys
->
dk_nentries
++
;
assert
(
mp
->
ma_keys
->
dk_usable
>=
0
);
}
else
if
(
*
value_addr
==
NULL
)
{
value
=
defaultobj
;
assert
(
_PyDict_HasSplitTable
(
mp
));
assert
(
ix
==
mp
->
ma_used
);
Py_INCREF
(
value
);
MAINTAIN_TRACKING
(
mp
,
key
,
value
);
*
value_addr
=
value
;
mp
->
ma_used
++
;
mp
->
ma_version_tag
=
DICT_NEXT_VERSION
();
assert
(
_PyDict_CheckConsistency
(
mp
));
}
else
{
val
=
*
value_addr
;
val
ue
=
*
value_addr
;
}
return
val
;
assert
(
_PyDict_CheckConsistency
(
mp
));
return
value
;
}
static
PyObject
*
...
...
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