use "len(buf)-1" to access final slice index to eliminate a few more boundary checks #160
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Also learnt in the process that when it comes to boundary checking Go doesn't seem to trust its own allocated slice length (though I'm assuming this wasn't a choice). So any slice allocated with a variable length, even if you know it's at least literal
x
because the length isx+$uintVariable
, it still performs boundary checks on all the slice indices up tox-1
unless you put a manual check directly after the slice allocation. There were a few cases of these that could be added here, but given it's an almost pointlessly small optimization that frankly has a weird "code smell" (given you're checking the length of a slice directly after allocating it), I didn't bother including them. Though I might see if there's an issue open for it on the Go project.