Skip to content
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

Faster Clone() in kv/key.go #11957

Merged
merged 2 commits into from
Sep 10, 2019
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: 6 additions & 4 deletions kv/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Key []byte
// Next returns the next key in byte-order.
func (k Key) Next() Key {
// add 0x0 to the end of key
buf := make([]byte, len([]byte(k))+1)
buf := make([]byte, len(k)+1)
copy(buf, []byte(k))
return buf
}
Expand All @@ -41,7 +41,7 @@ func (k Key) Next() Key {
// If we seek 'rowkey1' Next, we will get 'rowkey1_column1'.
// If we seek 'rowkey1' PrefixNext, we will get 'rowkey2'.
func (k Key) PrefixNext() Key {
buf := make([]byte, len([]byte(k)))
buf := make([]byte, len(k))
copy(buf, []byte(k))
var i int
for i = len(k) - 1; i >= 0; i-- {
Expand All @@ -68,9 +68,11 @@ func (k Key) HasPrefix(prefix Key) bool {
return bytes.HasPrefix(k, prefix)
}

// Clone returns a copy of the Key.
// Clone returns a deep copy of the Key.
func (k Key) Clone() Key {
return append([]byte(nil), k...)
ck := make([]byte, len(k))
copy(ck, []byte(k))
return ck
}

// String implements fmt.Stringer interface.
Expand Down