-
Notifications
You must be signed in to change notification settings - Fork 121
refactor: keep same api as v0.14.0 for SplitFirst/SplitLast #271
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,26 +64,26 @@ func StringCast(s string) Multiaddr { | |
| } | ||
|
|
||
| // SplitFirst returns the first component and the rest of the multiaddr. | ||
| func SplitFirst(m Multiaddr) (Component, Multiaddr) { | ||
| func SplitFirst(m Multiaddr) (*Component, Multiaddr) { | ||
| if m.Empty() { | ||
| return Component{}, nil | ||
| return nil, nil | ||
| } | ||
| if len(m) == 1 { | ||
| return m[0], nil | ||
| return &m[0], nil | ||
| } | ||
| return m[0], m[1:] | ||
| return &m[0], m[1:] | ||
| } | ||
|
|
||
| // SplitLast returns the rest of the multiaddr and the last component. | ||
| func SplitLast(m Multiaddr) (Multiaddr, Component) { | ||
| func SplitLast(m Multiaddr) (Multiaddr, *Component) { | ||
| if m.Empty() { | ||
| return nil, Component{} | ||
| return nil, nil | ||
| } | ||
| if len(m) == 1 { | ||
| // We want to explicitly return a nil slice if the prefix is now empty. | ||
| return nil, m[0] | ||
| return nil, &m[0] | ||
| } | ||
| return m[:len(m)-1], m[len(m)-1] | ||
| return m[:len(m)-1], &m[len(m)-1] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks unsafe. last points to the last element in the slice. So appends to the first bit(the multiaddr) will modify last, right?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same argument also applies to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a defensive copy |
||
| } | ||
|
|
||
| // SplitFunc splits the multiaddr when the callback first returns true. The | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
should we make these slices with a higher capacity?
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 hard to predict how a user will use this. If they want a higher capacity they should just use the slice of Components directly