-
Notifications
You must be signed in to change notification settings - Fork 20.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use slices
package for most sorting
#27474
Closed
danlaine
wants to merge
40
commits into
ethereum:master
from
danlaine:use-slices-package-for-sorting
Closed
Changes from 37 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
f1b2b48
trie; use slices.SortFunc instead of sort.Sort
9aa1958
trie; use slices.SortFunc instead of sort.Sort
c81918c
stacktrie; use slices.SortFunc instead of sort.Sort
6992248
rangeproof; use slices.SortFunc instead of sort.Sort
0e112ed
tests; use slices.Sort instead of sort.Sort
7f11a8c
apitypes; use slices.Sort instead of sort.Sort
e3e3605
tests; use slices.Sort instead of sort.Sort
39a44d4
main; use slices.Sort instead of sort.Strings
dd12c97
main, console, vm, fetcher, dbtest, memorydb, jsre, les, prometheus, …
2fc0108
msgrate; use slices method instead of sort method for sorting
7b38713
dnsdisc; use slices method instead of sort method for sorting
97d2de6
discover; use slices method instead of sort method for sorting
1b96e1c
discover; use slices method instead of sort method for sorting
cf1cb36
discover; use slices method instead of sort method for sorting
49f8dd5
discover; use slices method instead of sort method for sorting
9a75f71
discover; use slices method instead of sort method for sorting
6860c9f
p2p; use slices method instead of sort method for sorting
767c7b7
metrics; use slices method instead of sort method for sorting
340d73e
metrics; use slices method instead of sort method for sorting
2ca34c0
metrics; use slices method instead of sort method for sorting
08498ee
utils; use slices method instead of sort method for sorting
ea340cb
les; use slices method instead of sort method for sorting
92513a5
ethapi; use slices method instead of sort method for sorting
d49f65b
tracers; use slices method instead of sort method for sorting
b388208
dbtest; use slices method instead of sort method for sorting
9a79c5a
snap, gasprice; use slices method instead of sort method for sorting
4220502
eth, gasprice; use slices method instead of sort method for sorting
d167778
txpool; use slices method instead of sort method for sorting
bdd8e7e
build, devp2p, clique, forkid, core; use slices method instead of sor…
dde34cd
devp2p, core; use slices method instead of sort method for sorting
224b66f
trie; revert sorting changes
7bbc72a
trie; revert sorting changes
03b94ee
utils; remove dropListItem.Less
d1384ff
snap; revert changes
890aa4a
gasprice,trie; use slices method instead of sort method for sorting
818e751
snap; use slices method instead of sort method for sorting
5d92f12
keystore, snapshot; use slices method instead of sort method for sorting
fcd9dbb
p2p; implement capLessFunc to replace Cap.Less
3dcea2f
keystore; fix typo
3510e8e
metrics; use namedMetricsLessFunc instead of Less function
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ package clique | |
import ( | ||
"bytes" | ||
"encoding/json" | ||
"sort" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
|
@@ -29,6 +28,7 @@ import ( | |
"github.com/ethereum/go-ethereum/ethdb" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/params" | ||
"golang.org/x/exp/slices" | ||
) | ||
|
||
// Vote represents a single vote that an authorized signer made to modify the | ||
|
@@ -62,13 +62,6 @@ type Snapshot struct { | |
Tally map[common.Address]Tally `json:"tally"` // Current vote tally to avoid recalculating | ||
} | ||
|
||
// signersAscending implements the sort interface to allow sorting a list of addresses | ||
type signersAscending []common.Address | ||
|
||
func (s signersAscending) Len() int { return len(s) } | ||
func (s signersAscending) Less(i, j int) bool { return bytes.Compare(s[i][:], s[j][:]) < 0 } | ||
func (s signersAscending) Swap(i, j int) { s[i], s[j] = s[j], s[i] } | ||
|
||
// newSnapshot creates a new snapshot with the specified startup parameters. This | ||
// method does not initialize the set of recent signers, so only ever use if for | ||
// the genesis block. | ||
|
@@ -315,7 +308,9 @@ func (s *Snapshot) signers() []common.Address { | |
for sig := range s.Signers { | ||
sigs = append(sigs, sig) | ||
} | ||
sort.Sort(signersAscending(sigs)) | ||
slices.SortFunc(sigs, func(a, b common.Address) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you could reasonably define a |
||
return bytes.Compare(a[:], b[:]) < 0 | ||
}) | ||
return sigs | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't want to add a
Less
function onaccounts.Account
so did this instead