Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
4544dc5f
Unverified
Commit
4544dc5f
authored
Jun 19, 2023
by
Dan Laine
Committed by
GitHub
Jun 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/devp2p: use slices package for sorting (#27487)
parent
311b742c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
10 deletions
+10
-10
dns_route53.go
cmd/devp2p/dns_route53.go
+5
-5
nodeset.go
cmd/devp2p/nodeset.go
+5
-5
No files found.
cmd/devp2p/dns_route53.go
View file @
4544dc5f
...
...
@@ -20,7 +20,6 @@ import (
"context"
"errors"
"fmt"
"sort"
"strconv"
"strings"
"time"
...
...
@@ -33,6 +32,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/dnsdisc"
"github.com/urfave/cli/v2"
"golang.org/x/exp/slices"
)
const
(
...
...
@@ -288,11 +288,11 @@ func makeDeletionChanges(records map[string]recordSet, keep map[string]string) [
// sortChanges ensures DNS changes are in leaf-added -> root-changed -> leaf-deleted order.
func
sortChanges
(
changes
[]
types
.
Change
)
{
score
:=
map
[
string
]
int
{
"CREATE"
:
1
,
"UPSERT"
:
2
,
"DELETE"
:
3
}
s
ort
.
Slice
(
changes
,
func
(
i
,
j
int
)
bool
{
if
changes
[
i
]
.
Action
==
changes
[
j
]
.
Action
{
return
*
changes
[
i
]
.
ResourceRecordSet
.
Name
<
*
changes
[
j
]
.
ResourceRecordSet
.
Name
s
lices
.
SortFunc
(
changes
,
func
(
a
,
b
types
.
Change
)
bool
{
if
a
.
Action
==
b
.
Action
{
return
*
a
.
ResourceRecordSet
.
Name
<
*
b
.
ResourceRecordSet
.
Name
}
return
score
[
string
(
changes
[
i
]
.
Action
)]
<
score
[
string
(
changes
[
j
]
.
Action
)]
return
score
[
string
(
a
.
Action
)]
<
score
[
string
(
b
.
Action
)]
})
}
...
...
cmd/devp2p/nodeset.go
View file @
4544dc5f
...
...
@@ -21,11 +21,11 @@ import (
"encoding/json"
"fmt"
"os"
"sort"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/p2p/enode"
"golang.org/x/exp/slices"
)
const
jsonIndent
=
" "
...
...
@@ -77,8 +77,8 @@ func (ns nodeSet) nodes() []*enode.Node {
result
=
append
(
result
,
n
.
N
)
}
// Sort by ID.
s
ort
.
Slice
(
result
,
func
(
i
,
j
int
)
bool
{
return
bytes
.
Compare
(
result
[
i
]
.
ID
()
.
Bytes
(),
result
[
j
]
.
ID
()
.
Bytes
())
<
0
s
lices
.
SortFunc
(
result
,
func
(
a
,
b
*
enode
.
Node
)
bool
{
return
bytes
.
Compare
(
a
.
ID
()
.
Bytes
(),
b
.
ID
()
.
Bytes
())
<
0
})
return
result
}
...
...
@@ -103,8 +103,8 @@ func (ns nodeSet) topN(n int) nodeSet {
for
_
,
v
:=
range
ns
{
byscore
=
append
(
byscore
,
v
)
}
s
ort
.
Slice
(
byscore
,
func
(
i
,
j
int
)
bool
{
return
byscore
[
i
]
.
Score
>=
byscore
[
j
]
.
Score
s
lices
.
SortFunc
(
byscore
,
func
(
a
,
b
nodeJSON
)
bool
{
return
a
.
Score
>=
b
.
Score
})
result
:=
make
(
nodeSet
,
n
)
for
_
,
v
:=
range
byscore
[
:
n
]
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment