mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
use seamless slices for List.dropAt when possible
This commit is contained in:
parent
4ced1bcfdd
commit
cda37a5d1b
1 changed files with 10 additions and 2 deletions
|
@ -615,9 +615,17 @@ pub fn listDropAt(
|
||||||
drop_index: usize,
|
drop_index: usize,
|
||||||
dec: Dec,
|
dec: Dec,
|
||||||
) callconv(.C) RocList {
|
) 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) {
|
if (drop_index >= size) {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue