mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-04-15 15:04:51 +00:00
*: use cmp.Or where appropriate
It's slightly less efficient (all comparisons are always made), but for strings/ints it's negligible performance difference, while the code looks a tiny bit better. Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
357bc76882
commit
a50723ff72
3 changed files with 12 additions and 15 deletions
|
@ -200,11 +200,10 @@ func queryCandidates(ctx *cli.Context) error {
|
||||||
if !a.Active && b.Active {
|
if !a.Active && b.Active {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
res := cmp.Compare(a.Votes, b.Votes)
|
return cmp.Or(
|
||||||
if res != 0 {
|
cmp.Compare(a.Votes, b.Votes),
|
||||||
return res
|
a.PublicKey.Cmp(&b.PublicKey),
|
||||||
}
|
)
|
||||||
return a.PublicKey.Cmp(&b.PublicKey)
|
|
||||||
})
|
})
|
||||||
var res []byte
|
var res []byte
|
||||||
res = fmt.Appendf(res, "Key\tVotes\tCommittee\tConsensus\n")
|
res = fmt.Appendf(res, "Key\tVotes\tCommittee\tConsensus\n")
|
||||||
|
|
|
@ -363,11 +363,10 @@ func (c *ContractMD) AddMethod(md *MethodAndPrice, desc *manifest.Method) {
|
||||||
desc.Safe = md.RequiredFlags&(callflag.All^callflag.ReadOnly) == 0
|
desc.Safe = md.RequiredFlags&(callflag.All^callflag.ReadOnly) == 0
|
||||||
|
|
||||||
index, _ := slices.BinarySearchFunc(c.methods, *md, func(e, t MethodAndPrice) int {
|
index, _ := slices.BinarySearchFunc(c.methods, *md, func(e, t MethodAndPrice) int {
|
||||||
res := cmp.Compare(e.MD.Name, t.MD.Name)
|
return cmp.Or(
|
||||||
if res != 0 {
|
cmp.Compare(e.MD.Name, t.MD.Name),
|
||||||
return res
|
cmp.Compare(len(e.MD.Parameters), len(t.MD.Parameters)),
|
||||||
}
|
)
|
||||||
return cmp.Compare(len(e.MD.Parameters), len(t.MD.Parameters))
|
|
||||||
})
|
})
|
||||||
c.methods = slices.Insert(c.methods, index, *md)
|
c.methods = slices.Insert(c.methods, index, *md)
|
||||||
|
|
||||||
|
|
|
@ -63,11 +63,10 @@ func (a *ABI) IsValid() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if sliceHasDups(a.Methods, func(a, b Method) int {
|
if sliceHasDups(a.Methods, func(a, b Method) int {
|
||||||
res := cmp.Compare(a.Name, b.Name)
|
return cmp.Or(
|
||||||
if res != 0 {
|
cmp.Compare(a.Name, b.Name),
|
||||||
return res
|
cmp.Compare(len(a.Parameters), len(b.Parameters)),
|
||||||
}
|
)
|
||||||
return cmp.Compare(len(a.Parameters), len(b.Parameters))
|
|
||||||
}) {
|
}) {
|
||||||
return errors.New("duplicate method specifications")
|
return errors.New("duplicate method specifications")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue