@@ -498,9 +498,9 @@ impl ValueStack {
498498 let Some ( callee_end) = callee_start. checked_add ( callee_size) else {
499499 return Err ( TrapCode :: StackOverflow ) ;
500500 } ;
501- self . cells . resize ( callee_end, UntypedVal :: default ( ) ) ;
501+ self . grow_if_needed ( callee_end) ? ;
502502 let caller_sp = self . sp ( caller_start) ;
503- let cells = & mut self . cells [ callee_start..] ;
503+ let cells = & mut self . cells [ callee_start..callee_end ] ;
504504 let inout = FuncInOut :: new ( cells, params_len, results_len) ;
505505 let control = match caller {
506506 Some ( ( ip, _, instance) ) => ReturnCallHost :: Continue ( ( ip, caller_sp, instance) ) ,
@@ -528,27 +528,25 @@ impl ValueStack {
528528 let Some ( callee_end) = callee_start. checked_add ( callee_size) else {
529529 return Err ( TrapCode :: StackOverflow ) ;
530530 } ;
531- self . cells . resize ( callee_end, UntypedVal :: default ( ) ) ;
531+ self . grow_if_needed ( callee_end) ? ;
532532 let sp = self . sp ( caller_start) ;
533- let cells = & mut self . cells [ callee_start..] ;
533+ let cells = & mut self . cells [ callee_start..callee_end ] ;
534534 let inout = FuncInOut :: new ( cells, params_len, results_len) ;
535535 Ok ( ( sp, inout) )
536536 }
537537
538538 #[ inline( always) ]
539539 fn push ( & mut self , start : usize , len_slots : usize , len_params : u16 ) -> Result < Sp , TrapCode > {
540- debug_assert ! ( usize :: from( len_params) <= len_slots) ;
540+ let len_params = usize:: from ( len_params) ;
541+ debug_assert ! ( len_params <= len_slots) ;
541542 if len_slots == 0 {
542543 return Ok ( Sp :: dangling ( ) ) ;
543544 }
544545 let Some ( end) = start. checked_add ( len_slots) else {
545546 return Err ( TrapCode :: StackOverflow ) ;
546547 } ;
547- if end > self . max_height {
548- return Err ( TrapCode :: StackOverflow ) ;
549- }
550- self . cells . resize_with ( end, UntypedVal :: default) ;
551- let start_locals = start. wrapping_add ( usize:: from ( len_params) ) ;
548+ self . grow_if_needed ( end) ?;
549+ let start_locals = start. wrapping_add ( len_params) ;
552550 self . cells [ start_locals..end] . fill_with ( UntypedVal :: default) ;
553551 let sp = self . sp ( start) ;
554552 Ok ( sp)
@@ -570,20 +568,14 @@ impl ValueStack {
570568 let Some ( end) = start. checked_add ( len_slots) else {
571569 return Err ( TrapCode :: StackOverflow ) ;
572570 } ;
573- if end > self . max_height {
574- return Err ( TrapCode :: StackOverflow ) ;
575- }
576- let Some ( cells) = self . cells . get_mut ( start..) else {
571+ self . grow_if_needed ( end ) ? ;
572+ let params_len = usize :: from ( params_len ) ;
573+ let params_end = params_offset . wrapping_add ( params_len ) ;
574+ let Some ( cells) = self . cells . get_mut ( start..params_end ) else {
577575 unsafe { unreachable_unchecked ! ( ) }
578576 } ;
579- let params_end = params_offset. wrapping_add ( usize:: from ( params_len) ) ;
580577 cells. copy_within ( params_offset..params_end, 0 ) ;
581- self . cells . resize_with ( end, UntypedVal :: default) ;
582- let Some ( cells) = self . cells . get_mut ( start..end) else {
583- unsafe { unreachable_unchecked ! ( ) }
584- } ;
585- let locals_start = start. wrapping_add ( usize:: from ( params_len) ) ;
586- cells[ locals_start..] . fill_with ( UntypedVal :: default) ;
578+ cells[ params_len..] . fill_with ( UntypedVal :: default) ;
587579 let sp = self . sp ( start) ;
588580 Ok ( sp)
589581 }
0 commit comments