Skip to content

Commit

Permalink
Merge pull request #10679 from nvanbenschoten/nvanbenschoten/commitAlloc
Browse files Browse the repository at this point in the history
raft: Avoid allocation when boxing slice in maybeCommit
  • Loading branch information
xiang90 authored Apr 30, 2019
2 parents efcc108 + 208b8a3 commit 0bc219a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions raft/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,14 +607,14 @@ func (r *raft) maybeCommit() bool {
if cap(r.matchBuf) < len(r.prs) {
r.matchBuf = make(uint64Slice, len(r.prs))
}
mis := r.matchBuf[:len(r.prs)]
r.matchBuf = r.matchBuf[:len(r.prs)]
idx := 0
for _, p := range r.prs {
mis[idx] = p.Match
r.matchBuf[idx] = p.Match
idx++
}
sort.Sort(mis)
mci := mis[len(mis)-r.quorum()]
sort.Sort(&r.matchBuf)
mci := r.matchBuf[len(r.matchBuf)-r.quorum()]
return r.raftLog.maybeCommit(mci, r.Term)
}

Expand Down

0 comments on commit 0bc219a

Please sign in to comment.