aboutsummaryrefslogtreecommitdiffstats
path: root/p2p
diff options
context:
space:
mode:
authorOleg Kovalov <iamolegkovalov@gmail.com>2018-08-07 18:56:40 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-08-07 18:56:40 +0800
commitcf05ef9106779da0df62c0c03312fc489171aaa5 (patch)
treea2d5185dea85a478895b799da81e41f8e383cb52 /p2p
parentde9b0660acf26edc3b261b805c1a3454e3c76321 (diff)
downloaddexon-cf05ef9106779da0df62c0c03312fc489171aaa5.tar
dexon-cf05ef9106779da0df62c0c03312fc489171aaa5.tar.gz
dexon-cf05ef9106779da0df62c0c03312fc489171aaa5.tar.bz2
dexon-cf05ef9106779da0df62c0c03312fc489171aaa5.tar.lz
dexon-cf05ef9106779da0df62c0c03312fc489171aaa5.tar.xz
dexon-cf05ef9106779da0df62c0c03312fc489171aaa5.tar.zst
dexon-cf05ef9106779da0df62c0c03312fc489171aaa5.zip
p2p, swarm, trie: avoid copying slices in loops (#17265)
Diffstat (limited to 'p2p')
-rw-r--r--p2p/discover/table.go8
-rw-r--r--p2p/discv5/net_test.go2
-rw-r--r--p2p/discv5/table.go8
3 files changed, 9 insertions, 9 deletions
diff --git a/p2p/discover/table.go b/p2p/discover/table.go
index 8803daa56..0a554bbeb 100644
--- a/p2p/discover/table.go
+++ b/p2p/discover/table.go
@@ -160,7 +160,7 @@ func (tab *Table) ReadRandomNodes(buf []*Node) (n int) {
// Find all non-empty buckets and get a fresh slice of their entries.
var buckets [][]*Node
- for _, b := range tab.buckets {
+ for _, b := range &tab.buckets {
if len(b.entries) > 0 {
buckets = append(buckets, b.entries[:])
}
@@ -508,7 +508,7 @@ func (tab *Table) copyLiveNodes() {
defer tab.mutex.Unlock()
now := time.Now()
- for _, b := range tab.buckets {
+ for _, b := range &tab.buckets {
for _, n := range b.entries {
if now.Sub(n.addedAt) >= seedMinTableTime {
tab.db.updateNode(n)
@@ -524,7 +524,7 @@ func (tab *Table) closest(target common.Hash, nresults int) *nodesByDistance {
// obviously correct. I believe that tree-based buckets would make
// this easier to implement efficiently.
close := &nodesByDistance{target: target}
- for _, b := range tab.buckets {
+ for _, b := range &tab.buckets {
for _, n := range b.entries {
close.push(n, nresults)
}
@@ -533,7 +533,7 @@ func (tab *Table) closest(target common.Hash, nresults int) *nodesByDistance {
}
func (tab *Table) len() (n int) {
- for _, b := range tab.buckets {
+ for _, b := range &tab.buckets {
n += len(b.entries)
}
return n
diff --git a/p2p/discv5/net_test.go b/p2p/discv5/net_test.go
index 001d193cc..1a8137673 100644
--- a/p2p/discv5/net_test.go
+++ b/p2p/discv5/net_test.go
@@ -355,7 +355,7 @@ func (tn *preminedTestnet) mine(target NodeID) {
fmt.Printf(" target: %#v,\n", tn.target)
fmt.Printf(" targetSha: %#v,\n", tn.targetSha)
fmt.Printf(" dists: [%d][]NodeID{\n", len(tn.dists))
- for ld, ns := range tn.dists {
+ for ld, ns := range &tn.dists {
if len(ns) == 0 {
continue
}
diff --git a/p2p/discv5/table.go b/p2p/discv5/table.go
index c8d234b93..c793be508 100644
--- a/p2p/discv5/table.go
+++ b/p2p/discv5/table.go
@@ -81,7 +81,7 @@ func (tab *Table) chooseBucketRefreshTarget() common.Hash {
if printTable {
fmt.Println()
}
- for i, b := range tab.buckets {
+ for i, b := range &tab.buckets {
entries += len(b.entries)
if printTable {
for _, e := range b.entries {
@@ -93,7 +93,7 @@ func (tab *Table) chooseBucketRefreshTarget() common.Hash {
prefix := binary.BigEndian.Uint64(tab.self.sha[0:8])
dist := ^uint64(0)
entry := int(randUint(uint32(entries + 1)))
- for _, b := range tab.buckets {
+ for _, b := range &tab.buckets {
if entry < len(b.entries) {
n := b.entries[entry]
dist = binary.BigEndian.Uint64(n.sha[0:8]) ^ prefix
@@ -121,7 +121,7 @@ func (tab *Table) readRandomNodes(buf []*Node) (n int) {
// TODO: tree-based buckets would help here
// Find all non-empty buckets and get a fresh slice of their entries.
var buckets [][]*Node
- for _, b := range tab.buckets {
+ for _, b := range &tab.buckets {
if len(b.entries) > 0 {
buckets = append(buckets, b.entries[:])
}
@@ -175,7 +175,7 @@ func (tab *Table) closest(target common.Hash, nresults int) *nodesByDistance {
// obviously correct. I believe that tree-based buckets would make
// this easier to implement efficiently.
close := &nodesByDistance{target: target}
- for _, b := range tab.buckets {
+ for _, b := range &tab.buckets {
for _, n := range b.entries {
close.push(n, nresults)
}