Skip to content

Commit

Permalink
perf: simply do a pythonic result = list[:] to get a copy of all it…
Browse files Browse the repository at this point in the history
…ems to the new list
  • Loading branch information
Xmader committed Sep 24, 2024
1 parent 0eeda35 commit c63b609
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/PyListProxyHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -550,15 +550,7 @@ static bool array_concat(JSContext *cx, unsigned argc, JS::Value *vp) {
PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot);

Py_ssize_t selfSize = PyList_GET_SIZE(self);

PyObject *result = PyList_New(selfSize);

// Copy items to the new list
for (Py_ssize_t index = 0; index < selfSize; index++) {
PyObject *item = PyList_GetItem(self, index);
Py_INCREF(item); // `PyList_SetItem` steals the reference, so we must increase the reference count by 1
PyList_SetItem(result, index, item);
}
PyObject *result = PyList_GetSlice(self, 0, selfSize);

unsigned numArgs = args.length();
JS::RootedValue elementVal(cx);
Expand Down

0 comments on commit c63b609

Please sign in to comment.