Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions mypyc/lib-rt/vecs/vec_nested.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,7 @@ VecNested VecNested_Remove(VecNested self, VecNestedBufItem arg) {
if (i < self.len - 1) {
// Decref the removed item last, since it could run arbitrary code
VecNestedBufItem removed = items[i];
for (; i < self.len - 1; i++) {
items[i] = items[i + 1];
}
memmove(&items[i], &items[i + 1], (self.len - 1 - i) * sizeof(VecNestedBufItem));
VecNested_ItemXINCREF(self_buf, items[self.len - 1]);
VecNested_ItemXDECREF(self_buf, removed);
}
Expand Down Expand Up @@ -499,8 +497,7 @@ VecNestedPopResult VecNested_Pop(VecNested v, Py_ssize_t index) {
VecNestedBufItem *items = v.items;
VecNestedBufObject *v_buf = VEC_BUF(v);
result.f1 = items[index];
for (Py_ssize_t i = index; i < v.len - 1; i++)
items[i] = items[i + 1];
memmove(&items[index], &items[index + 1], (v.len - 1 - index) * sizeof(VecNestedBufItem));
if (v.len > 0)
VecNested_ItemXINCREF(v_buf, items[v.len - 1]);
v.len--;
Expand Down
7 changes: 2 additions & 5 deletions mypyc/lib-rt/vecs/vec_t.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,7 @@ VecT VecT_Remove(VecT v, PyObject *arg) {
if (i < v.len - 1) {
// Decref the removed item last, since it could run arbitrary code
PyObject *removed = items[i];
for (; i < v.len - 1; i++) {
items[i] = items[i + 1];
}
memmove(&items[i], &items[i + 1], (v.len - 1 - i) * sizeof(PyObject *));
// Keep a duplicate item, since there could be another reference
// to the buffer with a longer length, and they expect a valid reference.
Py_XINCREF(items[v.len - 1]);
Expand Down Expand Up @@ -546,8 +544,7 @@ VecTPopResult VecT_Pop(VecT v, Py_ssize_t index) {

PyObject **items = v.items;
result.f1 = items[index];
for (Py_ssize_t i = index; i < v.len - 1; i++)
items[i] = items[i + 1];
memmove(&items[index], &items[index + 1], (v.len - 1 - index) * sizeof(PyObject *));
// Keep duplicate item, since there could be another reference
// to the buffer with a longer length, and they expect a valid reference.
Py_XINCREF(items[v.len - 1]);
Expand Down
8 changes: 2 additions & 6 deletions mypyc/lib-rt/vecs/vec_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,7 @@ PyObject *FUNC(ToTuple)(VEC v) {
VEC FUNC(Remove)(VEC v, ITEM_C_TYPE x) {
for (Py_ssize_t i = 0; i < v.len; i++) {
if (v.items[i] == x) {
for (; i < v.len - 1; i++) {
v.items[i] = v.items[i + 1];
}
memmove(&v.items[i], &v.items[i + 1], (v.len - 1 - i) * sizeof(ITEM_C_TYPE));
v.len--;
// Return the stolen reference without INCREF
return v;
Expand Down Expand Up @@ -678,9 +676,7 @@ NAME(PopResult) FUNC(Pop)(VEC v, Py_ssize_t index) {
}

result.f1 = v.items[index];
for (Py_ssize_t i = index; i < v.len - 1; i++) {
v.items[i] = v.items[i + 1];
}
memmove(&v.items[index], &v.items[index + 1], (v.len - 1 - index) * sizeof(ITEM_C_TYPE));

v.len--;
// Return the stolen reference without INCREF
Expand Down
Loading