Stream: ideas

Topic: List.dropFirst returning slice?


view this post on Zulip Richard Feldman (Jul 05 2023 at 23:52):

currently, List.dropFirst is the same as List.dropAt 0, which clones the entire list except the first element into a new list.

however, if we specifically know we're dropping the first element, we have the option of returning a seamless slice of the original list—meaning that instead of cloning the entire list, we would bump its refcount by 1.

should we do that? thoughts?

view this post on Zulip Brendan Hansknecht (Jul 06 2023 at 04:15):

Already dealt with

view this post on Zulip Brendan Hansknecht (Jul 06 2023 at 04:15):

Look at the zig built-in for List.sublist

view this post on Zulip Brendan Hansknecht (Jul 06 2023 at 04:16):

That said, it is a tiny bit less optimal cause it calls the generic function which then runs an if to check if it is dropping the beginning of the list and if it is unique or not. So if List.sublist isnt inlined, it is a bit extra work.

view this post on Zulip Brendan Hansknecht (Jul 06 2023 at 04:17):

That said, I'm not sure what option we take if the list is unique. I think we shift in place, but we may make a seamless slice. That is up to us if we want to change the default.


Last updated: Jun 16 2026 at 16:19 UTC