mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #14374 from Comolli/main
Reduce redundant code and memory allocation.
This commit is contained in:
commit
77773c7798
@ -183,8 +183,7 @@ func (c MajorityConfig) VoteResult(votes map[uint64]bool) VoteResult {
|
|||||||
return VoteWon
|
return VoteWon
|
||||||
}
|
}
|
||||||
|
|
||||||
ny := [2]int{} // vote counts for no and yes, respectively
|
var votedCnt int //vote counts for yes.
|
||||||
|
|
||||||
var missing int
|
var missing int
|
||||||
for id := range c {
|
for id := range c {
|
||||||
v, ok := votes[id]
|
v, ok := votes[id]
|
||||||
@ -193,17 +192,15 @@ func (c MajorityConfig) VoteResult(votes map[uint64]bool) VoteResult {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if v {
|
if v {
|
||||||
ny[1]++
|
votedCnt++
|
||||||
} else {
|
|
||||||
ny[0]++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
q := len(c)/2 + 1
|
q := len(c)/2 + 1
|
||||||
if ny[1] >= q {
|
if votedCnt >= q {
|
||||||
return VoteWon
|
return VoteWon
|
||||||
}
|
}
|
||||||
if ny[1]+missing >= q {
|
if votedCnt+missing >= q {
|
||||||
return VotePending
|
return VotePending
|
||||||
}
|
}
|
||||||
return VoteLost
|
return VoteLost
|
||||||
|
Loading…
x
Reference in New Issue
Block a user