Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

perf(wasi): avoid extra allocations in inherit_env/args (#12431)

MoNyAvA68426f1a947e
diff --git a/crates/wasi/src/ctx.rs b/crates/wasi/src/ctx.rs
index 568e72f96e..93646da705 100644
--- a/crates/wasi/src/ctx.rs
+++ b/crates/wasi/src/ctx.rs
@@ -217,7 +217,8 @@ impl WasiCtxBuilder {
/// This will use [`envs`](WasiCtxBuilder::envs) to append all host-defined
/// environment variables.
pub fn inherit_env(&mut self) -> &mut Self {
- self.envs(&std::env::vars().collect::<Vec<(String, String)>>())
+ self.cli.environment.extend(std::env::vars());
+ self
}
/// Appends a list of arguments to the argument array to pass to wasm.
@@ -237,7 +238,8 @@ impl WasiCtxBuilder {
/// Appends all host process arguments to the list of arguments to get
/// passed to wasm.
pub fn inherit_args(&mut self) -> &mut Self {
- self.args(&std::env::args().collect::<Vec<String>>())
+ self.cli.arguments.extend(std::env::args());
+ self
}
/// Configures a "preopened directory" to be available to WebAssembly.