forked from TrueCloudLab/frostfs-contract
[#222] common: Optimize RemoveVote
Use single `REMOVE` instead of multiple `APPEND` opcodes. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
53795324dc
commit
aee1a5d77c
1 changed files with 7 additions and 5 deletions
|
@ -80,18 +80,20 @@ func Vote(ctx storage.Context, id, from []byte) int {
|
||||||
// inner ring nodes.
|
// inner ring nodes.
|
||||||
func RemoveVotes(ctx storage.Context, id []byte) {
|
func RemoveVotes(ctx storage.Context, id []byte) {
|
||||||
var (
|
var (
|
||||||
newCandidates []Ballot
|
|
||||||
candidates = getBallots(ctx)
|
candidates = getBallots(ctx)
|
||||||
|
index int
|
||||||
)
|
)
|
||||||
|
|
||||||
for i := 0; i < len(candidates); i++ {
|
for i := 0; i < len(candidates); i++ {
|
||||||
cnd := candidates[i]
|
cnd := candidates[i]
|
||||||
if !BytesEqual(cnd.ID, id) {
|
if BytesEqual(cnd.ID, id) {
|
||||||
newCandidates = append(newCandidates, cnd)
|
index = i
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetSerialized(ctx, voteKey, newCandidates)
|
util.Remove(candidates, index)
|
||||||
|
SetSerialized(ctx, voteKey, candidates)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getBallots returns deserialized slice of vote ballots.
|
// getBallots returns deserialized slice of vote ballots.
|
||||||
|
|
Loading…
Reference in a new issue