Skip to content

Commit cf2eefd

Browse files
authored
Update list_ops.c implement CPyList_Copy()
implement the primitive list.copy() operation
1 parent 647d10d commit cf2eefd

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

mypyc/lib-rt/list_ops.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ PyObject *CPyList_Build(Py_ssize_t len, ...) {
2929
return res;
3030
}
3131

32+
PyObject *CPyList_Copy(PyObject *list) {
33+
if(PyList_CheckExact(list)) {
34+
return PyList_GetSlice(list, 0, PyList_GET_SIZE(list));
35+
}
36+
_Py_IDENTIFIER(copy);
37+
return _PyObject_CallMethodIdNoArgs(list, &PyID_copy);
38+
}
39+
3240
PyObject *CPyList_GetItemUnsafe(PyObject *list, CPyTagged index) {
3341
Py_ssize_t n = CPyTagged_ShortAsSsize_t(index);
3442
PyObject *result = PyList_GET_ITEM(list, n);

0 commit comments

Comments
 (0)