Skip to content

Commit 44226b4

Browse files
committed
Changes from review
1 parent 11c64a6 commit 44226b4

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

Objects/listobject.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ list_clear_slot(PyObject *self)
891891
// Pointer-by-pointer memmove for PyObject** arrays that is safe
892892
// for shared lists in Py_GIL_DISABLED builds.
893893
static void
894-
list_atomic_memmove(PyListObject *a, PyObject **dest, PyObject **src, Py_ssize_t n)
894+
ptr_wise_atomic_memmove(PyListObject *a, PyObject **dest, PyObject **src, Py_ssize_t n)
895895
{
896896
#ifndef Py_GIL_DISABLED
897897
memmove(dest, src, n * sizeof(PyObject *));
@@ -987,7 +987,7 @@ list_ass_slice_lock_held(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyO
987987

988988
if (d < 0) { /* Delete -d items */
989989
Py_ssize_t tail = Py_SIZE(a) - ihigh;
990-
list_atomic_memmove(a, &item[ihigh+d], &item[ihigh], tail);
990+
ptr_wise_atomic_memmove(a, &item[ihigh+d], &item[ihigh], tail);
991991
(void)list_resize(a, Py_SIZE(a) + d); // NB: shrinking a list can't fail
992992
item = a->ob_item;
993993
}
@@ -996,7 +996,7 @@ list_ass_slice_lock_held(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyO
996996
if (list_resize(a, k+d) < 0)
997997
goto Error;
998998
item = a->ob_item;
999-
list_atomic_memmove(a, &item[ihigh+d], &item[ihigh], k - ihigh);
999+
ptr_wise_atomic_memmove(a, &item[ihigh+d], &item[ihigh], k - ihigh);
10001000
}
10011001
for (k = 0; k < n; k++, ilow++) {
10021002
PyObject *w = vitem[k];
@@ -1084,19 +1084,11 @@ list_inplace_repeat_lock_held(PyListObject *self, Py_ssize_t n)
10841084
_Py_memory_repeat((char *)items, sizeof(PyObject *)*output_size,
10851085
sizeof(PyObject *)*input_size);
10861086
#else
1087-
if (_Py_IsOwnedByCurrentThread((PyObject *)self) && !_PyObject_GC_IS_SHARED(self)) {
1088-
// No other threads can read this list concurrently, so atomic repeat is not necessary.
1089-
_Py_memory_repeat((char *)items, sizeof(PyObject *)*output_size,
1090-
sizeof(PyObject *)*input_size);
1091-
return 0;
1092-
}
1093-
1094-
PyObject **src = items;
1095-
PyObject **dst = items + input_size;
1096-
Py_ssize_t remaining = output_size - input_size;
1097-
while (remaining > 0) {
1098-
_Py_atomic_store_ptr_release(dst++, *src++);
1099-
remaining--;
1087+
Py_ssize_t copied = input_size;
1088+
while (copied < output_size) {
1089+
Py_ssize_t items_to_copy = Py_MIN(copied, output_size - copied);
1090+
ptr_wise_atomic_memmove(self, items + copied, items, items_to_copy);
1091+
copied += items_to_copy;
11001092
}
11011093
#endif
11021094
return 0;
@@ -1593,8 +1585,8 @@ list_pop_impl(PyListObject *self, Py_ssize_t index)
15931585
}
15941586
Py_ssize_t size_after_pop = Py_SIZE(self) - 1;
15951587
if (index < size_after_pop) {
1596-
list_atomic_memmove(self, &items[index], &items[index+1],
1597-
size_after_pop - index);
1588+
ptr_wise_atomic_memmove(self, &items[index], &items[index+1],
1589+
size_after_pop - index);
15981590
}
15991591
list_resize(self, size_after_pop); // NB: shrinking a list can't fail
16001592
return v;

0 commit comments

Comments
 (0)