From 9bc271894355d4fa8bbb8da74630033114f83349 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 31 Mar 2018 09:38:31 -0700 Subject: [PATCH] Clean up a bit of duplication in codegen --- crates/backend/src/codegen.rs | 36 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs index f4df5702..17d81af6 100644 --- a/crates/backend/src/codegen.rs +++ b/crates/backend/src/codegen.rs @@ -415,33 +415,29 @@ impl ToTokens for ast::ImportFunction { abi_arguments.push(my_quote! { #name: <#t as ::wasm_bindgen::convert::WasmBoundary>::Abi }); - if i == 0 && is_method { - arg_conversions.push(my_quote! { - let #name = <#t as ::wasm_bindgen::convert::WasmBoundary> - ::into_abi(self, &mut __stack); - }); + let var = if i == 0 && is_method { + quote! { self } } else { - arg_conversions.push(my_quote! { - let #name = <#t as ::wasm_bindgen::convert::WasmBoundary> - ::into_abi(#name, &mut __stack); - }); - } + quote! { #name } + }; + arg_conversions.push(my_quote! { + let #name = <#t as ::wasm_bindgen::convert::WasmBoundary> + ::into_abi(#name, &mut __stack); + }); } ast::Type::ByMutRef(_) => panic!("urgh mut"), ast::Type::ByRef(ref t) => { abi_argument_names.push(name); abi_arguments.push(my_quote! { #name: u32 }); - if i == 0 && is_method { - arg_conversions.push(my_quote! { - let #name = <#t as ::wasm_bindgen::convert::ToRefWasmBoundary> - ::to_abi_ref(self, &mut __stack); - }); + let var = if i == 0 && is_method { + quote! { self } } else { - arg_conversions.push(my_quote! { - let #name = <#t as ::wasm_bindgen::convert::ToRefWasmBoundary> - ::to_abi_ref(#name, &mut __stack); - }); - } + quote! { #name } + }; + arg_conversions.push(my_quote! { + let #name = <#t as ::wasm_bindgen::convert::ToRefWasmBoundary> + ::to_abi_ref(#var, &mut __stack); + }); } } }