Skip to content

Commit 6dd8f1c

Browse files
authored
cli-support: Remove Node.js specific passStringToWasm (#2310)
Now that Node has encodeInto it can use the same path as the normal Web Browser code (that avoids calling into the C++ code). Node 12,13, and 14 have this method, so it is now fairly well supported. We should check to see if this is actually a speedup for ASCII strings Signed-off-by: Joe Richey <[email protected]>
1 parent 09c5b82 commit 6dd8f1c

File tree

1 file changed

+0
-35
lines changed
  • crates/cli-support/src/js

1 file changed

+0
-35
lines changed

crates/cli-support/src/js/mod.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,37 +1003,6 @@ impl<'a> Context<'a> {
10031003
""
10041004
};
10051005

1006-
// If we are targeting Node.js, it doesn't have `encodeInto` yet
1007-
// but it does have `Buffer::write` which has similar semantics but
1008-
// doesn't require creating intermediate view using `subarray`
1009-
// and also has `Buffer::byteLength` to calculate size upfront.
1010-
if self.config.mode.nodejs() {
1011-
let get_buf = self.expose_node_buffer_memory(memory);
1012-
let ret = MemView {
1013-
name: "passStringToWasm",
1014-
num: get_buf.num,
1015-
};
1016-
if !self.should_write_global(ret.to_string()) {
1017-
return Ok(ret);
1018-
}
1019-
1020-
self.global(&format!(
1021-
"
1022-
function {}(arg, malloc) {{
1023-
{}
1024-
const len = Buffer.byteLength(arg);
1025-
const ptr = malloc(len);
1026-
{}().write(arg, ptr, len);
1027-
WASM_VECTOR_LEN = len;
1028-
return ptr;
1029-
}}
1030-
",
1031-
ret, debug, get_buf,
1032-
));
1033-
1034-
return Ok(ret);
1035-
}
1036-
10371006
let mem = self.expose_uint8_memory(memory);
10381007
let ret = MemView {
10391008
name: "passStringToWasm",
@@ -1532,10 +1501,6 @@ impl<'a> Context<'a> {
15321501
return ret;
15331502
}
15341503

1535-
fn expose_node_buffer_memory(&mut self, memory: MemoryId) -> MemView {
1536-
self.memview("getNodeBufferMemory", "Buffer.from", memory)
1537-
}
1538-
15391504
fn expose_int8_memory(&mut self, memory: MemoryId) -> MemView {
15401505
self.memview("getInt8Memory", "new Int8Array", memory)
15411506
}

0 commit comments

Comments
 (0)