Skip to content

Commit

Permalink
cli-support: Remove Node.js specific passStringToWasm (#2310)
Browse files Browse the repository at this point in the history
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 <joerichey@google.com>
  • Loading branch information
josephlr authored Sep 15, 2020
1 parent 09c5b82 commit 6dd8f1c
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,37 +1003,6 @@ impl<'a> Context<'a> {
""
};

// If we are targeting Node.js, it doesn't have `encodeInto` yet
// but it does have `Buffer::write` which has similar semantics but
// doesn't require creating intermediate view using `subarray`
// and also has `Buffer::byteLength` to calculate size upfront.
if self.config.mode.nodejs() {
let get_buf = self.expose_node_buffer_memory(memory);
let ret = MemView {
name: "passStringToWasm",
num: get_buf.num,
};
if !self.should_write_global(ret.to_string()) {
return Ok(ret);
}

self.global(&format!(
"
function {}(arg, malloc) {{
{}
const len = Buffer.byteLength(arg);
const ptr = malloc(len);
{}().write(arg, ptr, len);
WASM_VECTOR_LEN = len;
return ptr;
}}
",
ret, debug, get_buf,
));

return Ok(ret);
}

let mem = self.expose_uint8_memory(memory);
let ret = MemView {
name: "passStringToWasm",
Expand Down Expand Up @@ -1532,10 +1501,6 @@ impl<'a> Context<'a> {
return ret;
}

fn expose_node_buffer_memory(&mut self, memory: MemoryId) -> MemView {
self.memview("getNodeBufferMemory", "Buffer.from", memory)
}

fn expose_int8_memory(&mut self, memory: MemoryId) -> MemView {
self.memview("getInt8Memory", "new Int8Array", memory)
}
Expand Down

0 comments on commit 6dd8f1c

Please sign in to comment.