From e736396132fa8e6950061a99fc0873102273e9e9 Mon Sep 17 00:00:00 2001 From: Jeffrey Charles Date: Thu, 5 Dec 2024 18:58:21 -0500 Subject: [PATCH] Slight optimization in codegen (#856) --- crates/cli/src/codegen/mod.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/crates/cli/src/codegen/mod.rs b/crates/cli/src/codegen/mod.rs index 6fb4781f..017411e7 100644 --- a/crates/cli/src/codegen/mod.rs +++ b/crates/cli/src/codegen/mod.rs @@ -149,16 +149,18 @@ impl Generator { .make_linker(Some(Rc::new(move |engine| { let mut linker = Linker::new(engine); wasmtime_wasi::preview1::add_to_linker_sync(&mut linker, move |cx| { - // The underlying buffer backing the pipe is an Arc - // so the cloning should be fast. - let config = STDIN_PIPE.get().unwrap().clone(); - cx.wasi_ctx = Some( - WasiCtxBuilder::new() - .stdin(config) - .inherit_stdout() - .inherit_stderr() - .build_p1(), - ); + if cx.wasi_ctx.is_none() { + // The underlying buffer backing the pipe is an Arc + // so the cloning should be fast. + let config = STDIN_PIPE.get().unwrap().clone(); + cx.wasi_ctx = Some( + WasiCtxBuilder::new() + .stdin(config) + .inherit_stdout() + .inherit_stderr() + .build_p1(), + ); + } cx.wasi_ctx.as_mut().unwrap() })?; Ok(linker)