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
dms3
go-bitswap
Commits
bd024d24
Commit
bd024d24
authored
Dec 05, 2017
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bitswap: better wantlist allocation patterns
License: MIT Signed-off-by:
Steven Allen
<
steven@stebalien.com
>
parent
75294d22
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
16 deletions
+9
-16
bitswap.go
bitswap.go
+3
-2
wantlist/wantlist.go
wantlist/wantlist.go
+6
-14
No files found.
bitswap.go
View file @
bd024d24
...
...
@@ -451,8 +451,9 @@ func (bs *Bitswap) Close() error {
}
func
(
bs
*
Bitswap
)
GetWantlist
()
[]
*
cid
.
Cid
{
var
out
[]
*
cid
.
Cid
for
_
,
e
:=
range
bs
.
wm
.
wl
.
Entries
()
{
entries
:=
bs
.
wm
.
wl
.
Entries
()
out
:=
make
([]
*
cid
.
Cid
,
0
,
len
(
entries
))
for
_
,
e
:=
range
entries
{
out
=
append
(
out
,
e
.
Cid
)
}
return
out
...
...
wantlist/wantlist.go
View file @
bd024d24
...
...
@@ -126,7 +126,7 @@ func (w *ThreadSafe) Contains(k *cid.Cid) (*Entry, bool) {
func
(
w
*
ThreadSafe
)
Entries
()
[]
*
Entry
{
w
.
lk
.
RLock
()
defer
w
.
lk
.
RUnlock
()
var
es
entrySlice
es
:=
make
([]
*
Entry
,
0
,
len
(
w
.
set
))
for
_
,
e
:=
range
w
.
set
{
es
=
append
(
es
,
e
)
}
...
...
@@ -134,13 +134,8 @@ func (w *ThreadSafe) Entries() []*Entry {
}
func
(
w
*
ThreadSafe
)
SortedEntries
()
[]
*
Entry
{
w
.
lk
.
RLock
()
defer
w
.
lk
.
RUnlock
()
var
es
entrySlice
for
_
,
e
:=
range
w
.
set
{
es
=
append
(
es
,
e
)
}
sort
.
Sort
(
es
)
es
:=
w
.
Entries
()
sort
.
Sort
(
entrySlice
(
es
))
return
es
}
...
...
@@ -194,7 +189,7 @@ func (w *Wantlist) Contains(k *cid.Cid) (*Entry, bool) {
}
func
(
w
*
Wantlist
)
Entries
()
[]
*
Entry
{
var
es
entrySlice
es
:=
make
([]
*
Entry
,
0
,
len
(
w
.
set
))
for
_
,
e
:=
range
w
.
set
{
es
=
append
(
es
,
e
)
}
...
...
@@ -202,10 +197,7 @@ func (w *Wantlist) Entries() []*Entry {
}
func
(
w
*
Wantlist
)
SortedEntries
()
[]
*
Entry
{
var
es
entrySlice
for
_
,
e
:=
range
w
.
set
{
es
=
append
(
es
,
e
)
}
sort
.
Sort
(
es
)
es
:=
w
.
Entries
()
sort
.
Sort
(
entrySlice
(
es
))
return
es
}
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