From a708290adc457eef82bb3e625e32890316716ae5 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Tue, 15 Sep 2020 03:22:56 -0700 Subject: [PATCH] cli-support: Remove Node.js specific passStringToWasm 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 --- crates/cli-support/src/js/mod.rs | 35 -------------------------------- 1 file changed, 35 deletions(-) diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index cbec3136c1a..9fe2e99e25a 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -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", @@ -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) }