Skip to content

Commit

Permalink
all: use cmp.Compare
Browse files Browse the repository at this point in the history
  • Loading branch information
gitglorythegreat authored Dec 26, 2024
1 parent 341647f commit 291806c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 35 deletions.
9 changes: 2 additions & 7 deletions cmd/devp2p/dns_route53.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package main

import (
"cmp"
"context"
"errors"
"fmt"
Expand Down Expand Up @@ -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)])
})
}

Expand Down
9 changes: 2 additions & 7 deletions cmd/devp2p/nodeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package main

import (
"cmp"
"bytes"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -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] {
Expand Down
9 changes: 2 additions & 7 deletions core/state/snapshot/iterator_fast.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package snapshot

import (
"cmp"
"bytes"
"fmt"
"slices"
Expand Down Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions p2p/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package p2p

import (
"cmp"
"fmt"
"strings"

Expand Down Expand Up @@ -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)
}
9 changes: 2 additions & 7 deletions triedb/pathdb/iterator_fast.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package pathdb

import (
"cmp"
"bytes"
"fmt"
"slices"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 291806c

Please sign in to comment.