Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-peerstore
Commits
06edc321
Unverified
Commit
06edc321
authored
Jun 28, 2019
by
Steven Allen
Committed by
GitHub
Jun 28, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #86 from libp2p/fix/alloc-less
reduce allocations when adding addrs
parents
693780b7
491519a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
7 deletions
+7
-7
pstoremem/addr_book.go
pstoremem/addr_book.go
+7
-7
No files found.
pstoremem/addr_book.go
View file @
06edc321
...
...
@@ -154,10 +154,10 @@ func (mab *memoryAddrBook) AddAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Du
log
.
Warningf
(
"was passed nil multiaddr for %s"
,
p
)
continue
}
a
ddrstr
:=
string
(
addr
.
Bytes
()
)
a
,
found
:=
amap
[
addrstr
]
a
sBytes
:=
addr
.
Bytes
()
a
,
found
:=
amap
[
string
(
asBytes
)]
// won't allocate.
if
!
found
||
exp
.
After
(
a
.
Expires
)
{
amap
[
addrstr
]
=
&
expiringAddr
{
Addr
:
addr
,
Expires
:
exp
,
TTL
:
ttl
}
amap
[
string
(
asBytes
)
]
=
&
expiringAddr
{
Addr
:
addr
,
Expires
:
exp
,
TTL
:
ttl
}
mab
.
subManager
.
BroadcastAddr
(
p
,
addr
)
}
...
...
@@ -188,14 +188,14 @@ func (mab *memoryAddrBook) SetAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Du
log
.
Warningf
(
"was passed nil multiaddr for %s"
,
p
)
continue
}
// re-set all of them for new ttl.
addrstr
:=
string
(
addr
.
Bytes
())
// re-set all of them for new ttl.
aBytes
:=
addr
.
Bytes
()
if
ttl
>
0
{
amap
[
addrstr
]
=
&
expiringAddr
{
Addr
:
addr
,
Expires
:
exp
,
TTL
:
ttl
}
amap
[
string
(
aBytes
)
]
=
&
expiringAddr
{
Addr
:
addr
,
Expires
:
exp
,
TTL
:
ttl
}
mab
.
subManager
.
BroadcastAddr
(
p
,
addr
)
}
else
{
delete
(
amap
,
addrstr
)
delete
(
amap
,
string
(
aBytes
)
)
}
}
}
...
...
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