Skip to content

Commit c63b609

Browse files
committed
perf: simply do a pythonic result = list[:] to get a copy of all items to the new list
1 parent 0eeda35 commit c63b609

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

src/PyListProxyHandler.cc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -550,15 +550,7 @@ static bool array_concat(JSContext *cx, unsigned argc, JS::Value *vp) {
550550
PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot);
551551

552552
Py_ssize_t selfSize = PyList_GET_SIZE(self);
553-
554-
PyObject *result = PyList_New(selfSize);
555-
556-
// Copy items to the new list
557-
for (Py_ssize_t index = 0; index < selfSize; index++) {
558-
PyObject *item = PyList_GetItem(self, index);
559-
Py_INCREF(item); // `PyList_SetItem` steals the reference, so we must increase the reference count by 1
560-
PyList_SetItem(result, index, item);
561-
}
553+
PyObject *result = PyList_GetSlice(self, 0, selfSize);
562554

563555
unsigned numArgs = args.length();
564556
JS::RootedValue elementVal(cx);

0 commit comments

Comments
 (0)