@@ -208,10 +208,9 @@ impl Iterator for StackValueIter<'_> {
208208 }
209209 } ;
210210 self . position += 1 ;
211- let value = self . store . stack_value ( ty, & mut self . index ) ;
212211 Some (
213- value
214- . into_wasm ( self . store , ty )
212+ self . store
213+ . stack_value ( ty , & mut self . index )
215214 . unwrap_or_else ( |_| unreachable ! ( "invalid internal value at a typed host boundary" ) ) ,
216215 )
217216 }
@@ -391,28 +390,40 @@ impl Store {
391390 }
392391 }
393392
394- fn stack_value ( & self , ty : WasmType , index : & mut StackBase ) -> RuntimeValue {
395- match ty {
396- WasmType :: I32 | WasmType :: F32 | WasmType :: Ref ( _) => {
393+ #[ inline( always) ]
394+ fn stack_value ( & mut self , ty : WasmType , index : & mut StackBase ) -> Result < WasmValue > {
395+ Ok ( match ty {
396+ WasmType :: I32 => {
397397 let value = * self . value_stack . stack_32 . get ( index. s32 as usize ) ;
398398 index. s32 += 1 ;
399- if matches ! ( ty, WasmType :: Ref ( _) ) {
400- RuntimeValue :: ValueRef ( ValueRef :: from_raw ( value) )
401- } else {
402- RuntimeValue :: Value32 ( value)
403- }
399+ WasmValue :: I32 ( value as i32 )
400+ }
401+ WasmType :: F32 => {
402+ let value = * self . value_stack . stack_32 . get ( index. s32 as usize ) ;
403+ index. s32 += 1 ;
404+ WasmValue :: F32 ( f32:: from_bits ( value) )
405+ }
406+ WasmType :: I64 => {
407+ let value = * self . value_stack . stack_64 . get ( index. s64 as usize ) ;
408+ index. s64 += 1 ;
409+ WasmValue :: I64 ( value as i64 )
404410 }
405- WasmType :: I64 | WasmType :: F64 => {
411+ WasmType :: F64 => {
406412 let value = * self . value_stack . stack_64 . get ( index. s64 as usize ) ;
407413 index. s64 += 1 ;
408- RuntimeValue :: Value64 ( value)
414+ WasmValue :: F64 ( f64 :: from_bits ( value) )
409415 }
410416 WasmType :: V128 => {
411417 let value = * self . value_stack . stack_128 . get ( index. s128 as usize ) ;
412418 index. s128 += 1 ;
413- RuntimeValue :: Value128 ( value)
419+ WasmValue :: V128 ( value. 0 )
414420 }
415- }
421+ WasmType :: Ref ( ty) => {
422+ let value = ValueRef :: from_raw ( * self . value_stack . stack_32 . get ( index. s32 as usize ) ) ;
423+ index. s32 += 1 ;
424+ WasmValue :: Ref ( self . decode_ref ( value, ty) ?)
425+ }
426+ } )
416427 }
417428
418429 pub ( crate ) fn stack_value_iter (
@@ -428,7 +439,9 @@ impl Store {
428439 } ;
429440 let len = canonical. len ( ) ;
430441 let reference_count = canonical. iter ( ) . filter ( |ty| matches ! ( ty, WasmType :: Ref ( _) ) ) . count ( ) ;
431- self . state . roots . reserve ( reference_count) ?;
442+ if reference_count != 0 {
443+ self . state . roots . reserve ( reference_count) ?;
444+ }
432445 Ok ( StackValueIter { store : self , type_addr, types, index, position : 0 , len } )
433446 }
434447
@@ -453,8 +466,7 @@ impl Store {
453466 let mut index = base;
454467 for ( position, result) in results. iter_mut ( ) . enumerate ( ) {
455468 let ty = self . state . get_canonical_func_type ( type_addr) . results ( ) [ position] ;
456- let value = self . stack_value ( ty, & mut index) ;
457- * result = value. into_wasm ( self , ty) ?;
469+ * result = self . stack_value ( ty, & mut index) ?;
458470 }
459471 Ok ( ( ) )
460472 } ) ( ) ;
0 commit comments