-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
strings, bytes: divergent documentation for FieldsFunc functions #38630
Comments
Change https://golang.org/cl/229763 mentions this issue: |
Some context why I left that requirement in when I changed to code to not do two passes: This allows us to move to a two pass algorithm when lots of Fields are involved. This would be an optimization that would improve the current code by reducing allocations when the output has more than 32 Fields. I understand that since the current implementation will not crash and the optimization would still break code that didnt adhere to the comment so might invalidate the possibilty to change the code again even with the comment. I would like to keep the part that the function used should return consistent results to allow for a two pass algorithm. Would that be ok before we ship go1.15 and cant go back anymore? At least we should align the comment for bytes.FieldsFunc now that we changed strings.FieldsFunc. Line 448 in a9f8f02
I will send a change to align the comments again and remove the part about crashing. |
Change https://golang.org/cl/230797 mentions this issue: |
Fixes golang#38630 Change-Id: I0b2b693dd88821dcfc035cf552b687565bb55ef6 GitHub-Last-Rev: 291b1b4 GitHub-Pull-Request: golang#38631 Reviewed-on: https://go-review.googlesource.com/c/go/+/229763 Reviewed-by: Robert Griesemer <gri@golang.org>
golang.org/cl/229763 removed the documentation of requirements of the function passed to FieldsFunc. The current implementation does not require functions to return consistent results but this had not been the case for previous implementations. Add the requirement for consistent results back to the documentation to allow for future implementations to be more allocation efficient for an output with more than 32 fields. This is possible with a two pass algorithm first determining the number of fields used to allocate the output slice and then splitting the input into fields. While at it align the documentation of bytes.FieldsFunc with strings.FieldFunc. Fixes golang#38630 Change-Id: Iabbf9ca3dff0daa41f4ec930a21a3dd98e19f122 Reviewed-on: https://go-review.googlesource.com/c/go/+/230797 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
Read the documentation for
strings.FieldsFunc
What did you see?
I see that the documentation is out of date with respect to the following note.
This was appropriate when
FieldsForFunc
was using a two-pass logic. However, when the function was optimized to address #19789, this note is not correct anymore. The new implementation does only one-pass over the input. Hence, we can safely remove this note.The text was updated successfully, but these errors were encountered: