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
mf
go-multiaddr
Commits
62a88e01
Commit
62a88e01
authored
Nov 05, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
faster encapsulation + join
parent
9d041321
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
12 deletions
+21
-12
multiaddr.go
multiaddr.go
+4
-4
util.go
util.go
+17
-8
No files found.
multiaddr.go
View file @
62a88e01
...
...
@@ -84,10 +84,10 @@ func (m *multiaddr) Encapsulate(o Multiaddr) Multiaddr {
mb
:=
m
.
bytes
ob
:=
o
.
Bytes
()
var
b
bytes
.
Buffer
b
.
Write
(
mb
)
b
.
Write
(
ob
)
return
&
multiaddr
{
bytes
:
b
.
Bytes
()
}
b
:=
make
([]
byte
,
len
(
mb
)
+
len
(
ob
))
copy
(
b
,
mb
)
copy
(
b
[
len
(
mb
)
:
],
ob
)
return
&
multiaddr
{
bytes
:
b
}
}
// Decapsulate unwraps Multiaddr up until the given Multiaddr is found.
...
...
util.go
View file @
62a88e01
package
multiaddr
import
(
"bytes"
"fmt"
)
import
"fmt"
// Split returns the sub-address portions of a multiaddr.
func
Split
(
m
Multiaddr
)
[]
Multiaddr
{
...
...
@@ -21,11 +18,23 @@ func Split(m Multiaddr) []Multiaddr {
// Join returns a combination of addresses.
func
Join
(
ms
...
Multiaddr
)
Multiaddr
{
var
b
bytes
.
Buffer
for
_
,
m
:=
range
ms
{
b
.
Write
(
m
.
Bytes
())
length
:=
0
bs
:=
make
([][]
byte
,
len
(
ms
))
for
i
,
m
:=
range
ms
{
bs
[
i
]
=
m
.
Bytes
()
length
+=
len
(
bs
[
i
])
}
bidx
:=
0
b
:=
make
([]
byte
,
length
)
for
_
,
mb
:=
range
bs
{
for
i
:=
range
mb
{
b
[
bidx
]
=
mb
[
i
]
bidx
++
}
}
return
&
multiaddr
{
bytes
:
b
.
Bytes
()
}
return
&
multiaddr
{
bytes
:
b
}
}
// Cast re-casts a byte slice as a multiaddr. will panic if it fails to parse.
...
...
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