diff --git a/cmd/devp2p/dns_route53.go b/cmd/devp2p/dns_route53.go index a6125b8263a8..86907688f3b5 100644 --- a/cmd/devp2p/dns_route53.go +++ b/cmd/devp2p/dns_route53.go @@ -17,6 +17,7 @@ package main import ( + "cmp" "context" "errors" "fmt" @@ -292,13 +293,7 @@ func sortChanges(changes []types.Change) { if a.Action == b.Action { return strings.Compare(*a.ResourceRecordSet.Name, *b.ResourceRecordSet.Name) } - if score[string(a.Action)] < score[string(b.Action)] { - return -1 - } - if score[string(a.Action)] > score[string(b.Action)] { - return 1 - } - return 0 + return cmp.Compare(score[string(a.Action)], score[string(b.Action)]) }) } diff --git a/cmd/devp2p/nodeset.go b/cmd/devp2p/nodeset.go index 4fa862de14cb..0eb31be0038f 100644 --- a/cmd/devp2p/nodeset.go +++ b/cmd/devp2p/nodeset.go @@ -17,6 +17,7 @@ package main import ( + "cmp" "bytes" "encoding/json" "fmt" @@ -104,13 +105,7 @@ func (ns nodeSet) topN(n int) nodeSet { byscore = append(byscore, v) } slices.SortFunc(byscore, func(a, b nodeJSON) int { - if a.Score > b.Score { - return -1 - } - if a.Score < b.Score { - return 1 - } - return 0 + return cmp.Compare(b.Score, a.Score) }) result := make(nodeSet, n) for _, v := range byscore[:n] { diff --git a/core/state/snapshot/iterator_fast.go b/core/state/snapshot/iterator_fast.go index 7f7ba876ffbd..3ef2cece6126 100644 --- a/core/state/snapshot/iterator_fast.go +++ b/core/state/snapshot/iterator_fast.go @@ -17,6 +17,7 @@ package snapshot import ( + "cmp" "bytes" "fmt" "slices" @@ -45,13 +46,7 @@ func (it *weightedIterator) Cmp(other *weightedIterator) int { return 1 } // Same account/storage-slot in multiple layers, split by priority - if it.priority < other.priority { - return -1 - } - if it.priority > other.priority { - return 1 - } - return 0 + return cmp.Compare(it.priority, other.priority) } // fastIterator is a more optimized multi-layer iterator which maintains a diff --git a/p2p/protocol.go b/p2p/protocol.go index 9bb6785a2250..de3127e23365 100644 --- a/p2p/protocol.go +++ b/p2p/protocol.go @@ -17,6 +17,7 @@ package p2p import ( + "cmp" "fmt" "strings" @@ -81,13 +82,7 @@ func (cap Cap) String() string { // Cmp defines the canonical sorting order of capabilities. func (cap Cap) Cmp(other Cap) int { if cap.Name == other.Name { - if cap.Version < other.Version { - return -1 - } - if cap.Version > other.Version { - return 1 - } - return 0 + return cmp.Compare(cap.Version, other.Version) } return strings.Compare(cap.Name, other.Name) } diff --git a/triedb/pathdb/iterator_fast.go b/triedb/pathdb/iterator_fast.go index 217b211fccb1..24cd1635eb6f 100644 --- a/triedb/pathdb/iterator_fast.go +++ b/triedb/pathdb/iterator_fast.go @@ -17,6 +17,7 @@ package pathdb import ( + "cmp" "bytes" "fmt" "slices" @@ -45,13 +46,7 @@ func (it *weightedIterator) Cmp(other *weightedIterator) int { return 1 } // Same account/storage-slot in multiple layers, split by priority - if it.priority < other.priority { - return -1 - } - if it.priority > other.priority { - return 1 - } - return 0 + return cmp.Compare(it.priority, other.priority) } // fastIterator is a more optimized multi-layer iterator which maintains a