Skip to content

Commit 518c34e

Browse files
authored
Apply batched suggestions from code review
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
1 parent 3595cf8 commit 518c34e

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

‎Objects/dictobject.c‎

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4323,32 +4323,27 @@ clone_compact_dict_keys(PyDictObject *orig)
43234323
if (unicode) {
43244324
PyDictUnicodeEntry *src = DK_UNICODE_ENTRIES(oldkeys);
43254325
PyDictUnicodeEntry *dst = DK_UNICODE_ENTRIES(keys);
4326-
for (Py_ssize_t i = 0; n < used; i++) {
4327-
while (src[i].me_value == NULL) {
4328-
i++;
4326+
for (Py_ssize_t i = 0; i < used; i++) {
4327+
while (src->me_value == NULL) {
4328+
src++;
43294329
}
4330-
assert(i < oldkeys->dk_nentries);
4331-
dst[n].me_key = Py_NewRef(src[i].me_key);
4332-
dst[n].me_value = Py_NewRef(src[i].me_value);
4333-
n++;
4330+
dst[i] = *src++;
4331+
Py_INCREF(dst[i].me_key);
4332+
Py_INCREF(dst[i].me_value);
43344333
}
4335-
assert(n == used);
43364334
build_indices_unicode(keys, dst, n);
43374335
}
43384336
else {
43394337
PyDictKeyEntry *src = DK_ENTRIES(oldkeys);
43404338
PyDictKeyEntry *dst = DK_ENTRIES(keys);
4341-
for (Py_ssize_t i = 0; n < used; i++) {
4342-
while (src[i].me_value == NULL) {
4343-
i++;
4339+
for (Py_ssize_t i = 0; i < used; i++) {
4340+
while (src->me_value == NULL) {
4341+
src++;
43444342
}
4345-
assert(i < oldkeys->dk_nentries);
4346-
dst[n].me_key = Py_NewRef(src[i].me_key);
4347-
dst[n].me_hash = src[i].me_hash;
4348-
dst[n].me_value = Py_NewRef(src[i].me_value);
4349-
n++;
4343+
dst[i] = *src++;
4344+
Py_INCREF(dst[i].me_key);
4345+
Py_INCREF(dst[i].me_value);
43504346
}
4351-
assert(n == used);
43524347
build_indices_generic(keys, dst, n);
43534348
}
43544349
keys->dk_nentries = n;
@@ -4682,8 +4677,7 @@ copy_lock_held_untracked(PyObject *o, int as_frozendict)
46824677
return (PyObject *)split_copy;
46834678
}
46844679

4685-
if (Py_TYPE(mp)->tp_iter == dict_iter && mp->ma_values == NULL)
4686-
{
4680+
if (Py_TYPE(mp)->tp_iter == dict_iter) {
46874681
/* Use fast-copy if:
46884682
46894683
(1) type(mp) doesn't override tp_iter; and
@@ -4746,6 +4740,9 @@ copy_lock_held_untracked(PyObject *o, int as_frozendict)
47464740
if (res < 0) {
47474741
Py_DECREF(copy);
47484742
return NULL;
4743+
if (dict_merge(copy, o, 1, NULL) < 0) {
4744+
Py_DECREF(copy);
4745+
return NULL;
47494746
}
47504747

47514748
assert(!_PyObject_GC_IS_TRACKED(copy));

0 commit comments

Comments
 (0)