Misc cleanups (#5014)
* Replace resize+copy_from_slice with extend_from_slice Vec::resize initializes the new space, which is wasted effort if we're just going to call `copy_from_slice` on it immediately afterward. Using `extend_from_slice` is simpler, and very slightly faster. If the new size were bigger than the buffer we're copying from, then it would make sense to initialize the excess. But it isn't: it's always exactly the same size. * Move helpers from Context to CompiledCode These methods only use information from Context::compiled_code, so they should live on CompiledCode instead. * Remove an unnecessary #[cfg_attr] There are other uses of `#[allow(clippy::too_many_arguments)]` in this file, so apparently it doesn't need to be guarded by the "cargo-clippy" feature. * Fix a few comments Two of these were wrong/misleading: - `FunctionBuilder::new` does not clear the provided func_ctx. It does debug-assert that the context is already clear, but I don't think that's worth a comment. - `switch_to_block` does not "create values for the arguments." That's done by the combination of `append_block_params_for_function_params` and `declare_wasm_parameters`. * wasmtime-cranelift: Misc cleanups The main change is to use the `CompiledCode` reference we already had instead of getting it out of `Context` repeatedly. This removes a bunch of `unwrap()` calls. * wasmtime-cranelift: Factor out uncached compile
This commit is contained in:
@@ -39,10 +39,10 @@ impl SubTest for TestUnwind {
|
||||
let isa = context.isa.expect("unwind needs an ISA");
|
||||
let mut comp_ctx = cranelift_codegen::Context::for_function(func.into_owned());
|
||||
|
||||
comp_ctx.compile(isa).expect("failed to compile function");
|
||||
let code = comp_ctx.compile(isa).expect("failed to compile function");
|
||||
|
||||
let mut text = String::new();
|
||||
match comp_ctx.create_unwind_info(isa).expect("unwind info") {
|
||||
match code.create_unwind_info(isa).expect("unwind info") {
|
||||
Some(UnwindInfo::WindowsX64(info)) => {
|
||||
let mut mem = vec![0; info.emit_size()];
|
||||
info.emit(&mut mem);
|
||||
|
||||
Reference in New Issue
Block a user