Commit c137fc1d authored by Stefan Behnel's avatar Stefan Behnel

Lists of "negative" length are also empty, and that's the case we special-case...

Lists of "negative" length are also empty, and that's the case we special-case later in an inline function, so use the same condition for consistency and easy C compiler optimisation.

See https://github.com/cython/cython/pull/4734
parent 969deb4d
...@@ -858,9 +858,9 @@ static CYTHON_INLINE PyObject* __Pyx_Py{{type}}_GetSlice( ...@@ -858,9 +858,9 @@ static CYTHON_INLINE PyObject* __Pyx_Py{{type}}_GetSlice(
Py_ssize_t length = Py{{type}}_GET_SIZE(src); Py_ssize_t length = Py{{type}}_GET_SIZE(src);
__Pyx_crop_slice(&start, &stop, &length); __Pyx_crop_slice(&start, &stop, &length);
{{if type=='List'}} {{if type=='List'}}
if (length == 0) { if (length <= 0) {
// Avoid undefined behaviour when accessing `ob_item` of an empty list. // Avoid undefined behaviour when accessing `ob_item` of an empty list.
return PyList_New(0); return PyList_New(0);
} }
{{endif}} {{endif}}
return __Pyx_Py{{type}}_FromArray(((Py{{type}}Object*)src)->ob_item + start, length); return __Pyx_Py{{type}}_FromArray(((Py{{type}}Object*)src)->ob_item + start, length);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment