@@ -168,7 +168,7 @@ pub(crate) struct FunctionBuilder<'a> {
168168impl < ' a > FunctionBuilder < ' a > {
169169 pub ( crate ) fn new (
170170 metadata : & ' a ModuleMetadata ,
171- signature : Signature ,
171+ signature : & Signature ,
172172 local_types : Vec < ValueLane > ,
173173 local_addr_map : Vec < u16 > ,
174174 body_size : usize ,
@@ -188,7 +188,7 @@ impl<'a> FunctionBuilder<'a> {
188188 height: 0 ,
189189 base: ValueCounts :: default ( ) ,
190190 params: Vec :: new( ) ,
191- results: signature. results,
191+ results: signature. results. clone ( ) ,
192192 unreachable: false ,
193193 entry_unreachable: false ,
194194 end_reachable: false ,
@@ -402,7 +402,7 @@ pub(crate) fn process_operators(
402402 let body_size = body. as_bytes ( ) . len ( ) ;
403403 let reader = body. get_binary_reader_for_operators ( ) ?;
404404 let mut reader = OperatorsReader :: new_with_allocs ( reader, allocs) ;
405- let signature = metadata. signature ( ty_idx) ?. clone ( ) ;
405+ let signature = metadata. signature ( ty_idx) ?;
406406 let mut builder =
407407 FunctionBuilder :: new ( metadata, signature, local_types, local_addr_map, body_size, deduplicate_operands) ;
408408
@@ -436,7 +436,7 @@ pub(crate) fn process_operators_and_validate(
436436 let body_size = body. as_bytes ( ) . len ( ) ;
437437 let reader = body. get_binary_reader_for_operators ( ) ?;
438438 let mut reader = OperatorsReader :: new_with_allocs ( reader, allocs) ;
439- let signature = metadata. signature ( ty_idx) ?. clone ( ) ;
439+ let signature = metadata. signature ( ty_idx) ?;
440440 let mut builder =
441441 FunctionBuilder :: new ( metadata, signature, local_types, local_addr_map, body_size, deduplicate_operands) ;
442442
@@ -628,49 +628,47 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder<'_> {
628628 }
629629
630630 fn visit_call ( & mut self , function_index : u32 ) -> Self :: Output {
631- let signature = self . metadata . function_signature ( function_index) ?. clone ( ) ;
631+ let signature = self . metadata . function_signature ( function_index) ?;
632632 self . emit ( & signature. params , & signature. results , Instruction :: Call ( function_index) )
633633 }
634634
635635 fn visit_call_indirect ( & mut self , type_index : u32 , table_index : u32 ) -> Self :: Output {
636- let signature = self . metadata . signature ( type_index) ?. clone ( ) ;
637- let mut inputs = signature. params ;
638- inputs. push ( self . metadata . table_size ( table_index) ?) ;
636+ let table_size = self . metadata . table_size ( table_index) ?;
639637 let operand = self . push_operand ( TwoU32 { first : type_index, second : table_index } ) ?;
640- self . emit ( & inputs, & signature. results , Instruction :: CallIndirect ( operand) )
638+ let signature = self . metadata . signature ( type_index) ?;
639+ self . pop_expect ( table_size) ?;
640+ self . emit ( & signature. params , & signature. results , Instruction :: CallIndirect ( operand) )
641641 }
642642
643643 fn visit_call_ref ( & mut self , type_index : u32 ) -> Self :: Output {
644- let signature = self . metadata . signature ( type_index) ?. clone ( ) ;
645- let mut inputs = signature. params ;
646- inputs. push ( ValueLane :: S32 ) ;
647- self . emit ( & inputs, & signature. results , Instruction :: CallRef ( type_index) )
644+ let signature = self . metadata . signature ( type_index) ?;
645+ self . pop_expect ( ValueLane :: S32 ) ?;
646+ self . emit ( & signature. params , & signature. results , Instruction :: CallRef ( type_index) )
648647 }
649648
650649 fn visit_return_call ( & mut self , function_index : u32 ) -> Self :: Output {
651- let signature = self . metadata . function_signature ( function_index) ?. clone ( ) ;
650+ let signature = self . metadata . function_signature ( function_index) ?;
652651 self . apply_effect ( & signature. params , & [ ] ) ?;
653652 self . mark_unreachable ( ) ;
654653 self . instructions . push ( Instruction :: ReturnCall ( function_index) ) ;
655654 Ok ( ( ) )
656655 }
657656
658657 fn visit_return_call_indirect ( & mut self , type_index : u32 , table_index : u32 ) -> Self :: Output {
659- let signature = self . metadata . signature ( type_index ) ? . clone ( ) ;
660- let mut inputs = signature . params ;
661- inputs . push ( self . metadata . table_size ( table_index ) ? ) ;
662- self . apply_effect ( & inputs , & [ ] ) ?;
658+ let table_size = self . metadata . table_size ( table_index ) ? ;
659+ let signature = self . metadata . signature ( type_index ) ? ;
660+ self . pop_expect ( table_size ) ? ;
661+ self . apply_effect ( & signature . params , & [ ] ) ?;
663662 self . mark_unreachable ( ) ;
664663 let operand = self . push_operand ( TwoU32 { first : type_index, second : table_index } ) ?;
665664 self . instructions . push ( Instruction :: ReturnCallIndirect ( operand) ) ;
666665 Ok ( ( ) )
667666 }
668667
669668 fn visit_return_call_ref ( & mut self , type_index : u32 ) -> Self :: Output {
670- let signature = self . metadata . signature ( type_index) ?. clone ( ) ;
671- let mut inputs = signature. params ;
672- inputs. push ( ValueLane :: S32 ) ;
673- self . apply_effect ( & inputs, & [ ] ) ?;
669+ let signature = self . metadata . signature ( type_index) ?;
670+ self . pop_expect ( ValueLane :: S32 ) ?;
671+ self . apply_effect ( & signature. params , & [ ] ) ?;
674672 self . mark_unreachable ( ) ;
675673 self . instructions . push ( Instruction :: ReturnCallRef ( type_index) ) ;
676674 Ok ( ( ) )
@@ -838,7 +836,7 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder<'_> {
838836 }
839837
840838 fn visit_throw ( & mut self , tag_index : u32 ) -> Self :: Output {
841- let signature = self . metadata . tag_signature ( tag_index) ?. clone ( ) ;
839+ let signature = self . metadata . tag_signature ( tag_index) ?;
842840 self . apply_effect ( & signature. params , & [ ] ) ?;
843841 self . instructions . push ( Instruction :: Throw ( tag_index) ) ;
844842 self . mark_unreachable ( ) ;
0 commit comments