-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
slice.Remove #185
slice.Remove #185
Conversation
slice/remove.go
Outdated
package slice | ||
|
||
// Remove removes the given index range from the given slice, preserving element order. | ||
// It is the safer version of go/x/exp/slices.Delete() as it will |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just slices
package already - https://pkg.go.dev/slices#Delete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With one key difference: Delete panics if s[i:j] is not a valid slice of s
<- this function does not panic. That's what I was trying to get across with this comment. That snippet is pulled from that link btw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just meant that go/x/exp/slices
and build-in slices
are different packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh I see. I misread your comment, apologies!
8d8e898
to
14b6a71
Compare
28b8ccf
to
8fae945
Compare
slice.Remove
as a safer variant of the slices.Delete() function that avoids the panic case for invalid indeciesThis function does fall within the warning about potential memory leaks if the slices modified are long-lived. See slices.Delete() docs for more info
Implementation Notes
Benchmarking Checks
On an Intel Mac, to gut check the no-allocation claim: