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-ws-transport
Commits
709d2b3e
Unverified
Commit
709d2b3e
authored
Jan 09, 2020
by
Steven Allen
Committed by
GitHub
Jan 09, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #68 from libp2p/feat/fast-copy
feat: faster copy in wasm
parents
79f4bb33
9a9b0370
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
conn_browser.go
conn_browser.go
+5
-5
No files found.
conn_browser.go
View file @
709d2b3e
...
...
@@ -117,8 +117,8 @@ func (c *Conn) Write(b []byte) (n int, err error) {
return
0
,
err
}
uint8Array
:=
js
.
Global
()
.
Get
(
"Uint8Array"
)
.
New
(
len
(
b
))
for
i
,
bi
:=
range
b
{
uint8Array
.
SetIndex
(
i
,
bi
)
if
js
.
CopyBytesToJS
(
uint8Array
,
b
)
!=
len
(
b
)
{
panic
(
"expected to copy all bytes"
)
}
c
.
Call
(
"send"
,
uint8Array
.
Get
(
"buffer"
))
return
len
(
b
),
nil
...
...
@@ -262,10 +262,10 @@ func (c *Conn) waitForOpen() error {
// arrayBufferToBytes converts a JavaScript ArrayBuffer to a slice of bytes.
func
arrayBufferToBytes
(
buffer
js
.
Value
)
[]
byte
{
view
:=
js
.
Global
()
.
Get
(
"Uint8Array"
)
.
New
(
buffer
)
dataLen
:=
view
.
Get
(
"length"
)
.
Int
()
dataLen
:=
view
.
Length
()
data
:=
make
([]
byte
,
dataLen
)
for
i
:=
0
;
i
<
dataLen
;
i
++
{
data
[
i
]
=
byte
(
view
.
Index
(
i
)
.
Int
()
)
if
js
.
CopyBytesToGo
(
data
,
view
)
!=
dataLen
{
panic
(
"expected to copy all bytes"
)
}
return
data
}
...
...
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