use seamless slices for List.dropAt when possible

This commit is contained in:
Brendan Hansknecht 2023-03-11 10:56:38 -08:00
parent 4ced1bcfdd
commit cda37a5d1b
No known key found for this signature in database
GPG Key ID: 0EA784685083E75B

View File

@ -615,9 +615,17 @@ pub fn listDropAt(
drop_index: usize,
dec: Dec,
) callconv(.C) RocList {
if (list.bytes) |source_ptr| {
const size = list.len();
const size = list.len();
// If droping the first or last element, return a seamless slice.
// For simplicity, do this by calling listSublist.
// In the future, we can test if it is faster to manually inline the important parts here.
if (drop_index == 0) {
return listSublist(list, alignment, element_width, 1, size - 1, dec);
} else if (drop_index == size - 1) {
return listSublist(list, alignment, element_width, 0, size - 1, dec);
}
if (list.bytes) |source_ptr| {
if (drop_index >= size) {
return list;
}