Skip to content

Commit

Permalink
Merge pull request #10684 from nvanbenschoten/nvanbenschoten/appendAn…
Browse files Browse the repository at this point in the history
…dCopy

raft: Avoid multiple allocs when merging stable and unstable log
  • Loading branch information
xiang90 authored Apr 30, 2019
2 parents 0bc219a + b5593de commit e3f3753
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions raft/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,10 @@ func (l *raftLog) slice(lo, hi, maxSize uint64) ([]pb.Entry, error) {
if hi > l.unstable.offset {
unstable := l.unstable.slice(max(lo, l.unstable.offset), hi)
if len(ents) > 0 {
ents = append([]pb.Entry{}, ents...)
ents = append(ents, unstable...)
combined := make([]pb.Entry, len(ents)+len(unstable))
n := copy(combined, ents)
copy(combined[n:], unstable)
ents = combined
} else {
ents = unstable
}
Expand Down

0 comments on commit e3f3753

Please sign in to comment.