diff --git a/crates/wat/src/lib.rs b/crates/wat/src/lib.rs index d08d6ccebf..120bb4abbc 100644 --- a/crates/wat/src/lib.rs +++ b/crates/wat/src/lib.rs @@ -235,7 +235,18 @@ impl Parser { }), })?; match self.parse_bytes(Some(file), &contents) { - Ok(bytes) => Ok(bytes.into_owned()), + // If the result here is borrowed then that means that the input + // `&contents` was itself already a wasm module. We've already got + // an owned copy of that so return `contents` directly after + // double-checking it is indeed the same as the `bytes` return value + // here. That helps avoid a copy of `bytes` via something like + // `Cow::to_owned` which would otherwise copy the bytes. + Ok(Cow::Borrowed(bytes)) => { + assert_eq!(bytes.len(), contents.len()); + assert_eq!(bytes.as_ptr(), contents.as_ptr()); + Ok(contents) + } + Ok(Cow::Owned(bytes)) => Ok(bytes), Err(mut e) => { e.set_path(file); Err(e) diff --git a/src/bin/wasm-tools/validate.rs b/src/bin/wasm-tools/validate.rs index a065665df9..1ef778b90c 100644 --- a/src/bin/wasm-tools/validate.rs +++ b/src/bin/wasm-tools/validate.rs @@ -66,7 +66,9 @@ impl Opts { } pub fn run(&self) -> Result<()> { + let start = Instant::now(); let wasm = self.io.parse_input_wasm()?; + log::info!("read module in {:?}", start.elapsed()); // If validation fails then try to attach extra information to the // error based on DWARF information in the input wasm binary. If