Skip to content

roachpb: Use make and copy pattern for high profile byte slice copies #4963

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions roachpb/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,17 @@ func MakeKey(keys ...[]byte) []byte {
// BytesNext returns the next possible byte by appending an \x00.
func BytesNext(b []byte) []byte {
// TODO(spencer): Do we need to enforce KeyMaxLength here?
return append(append([]byte(nil), b...), 0)
// Switched to "make and copy" pattern in #4963 for performance.
bn := make([]byte, len(b)+1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to add a comment referring to the PR so that this isn't accidentally reverted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

copy(bn, b)
bn[len(bn)-1] = 0
return bn
}

func bytesPrefixEnd(b []byte) []byte {
end := append([]byte(nil), b...)
// Switched to "make and copy" pattern in #4963 for performance.
end := make([]byte, len(b))
copy(end, b)
for i := len(end) - 1; i >= 0; i-- {
end[i] = end[i] + 1
if end[i] != 0 {
Expand Down