2
2
3
3
use super :: Instruction ;
4
4
use alloc:: vec:: Vec ;
5
- use core:: ptr:: NonNull ;
6
5
use wasmi_arena:: Index ;
7
6
8
7
/// A reference to a Wasm function body stored in the [`CodeMap`].
@@ -102,7 +101,7 @@ impl CodeMap {
102
101
/// Returns an [`InstructionPtr`] to the instruction at [`InstructionsRef`].
103
102
#[ inline]
104
103
pub fn instr_ptr ( & self , iref : InstructionsRef ) -> InstructionPtr {
105
- InstructionPtr :: new ( & self . insts [ iref. start ] )
104
+ InstructionPtr :: new ( self . insts [ iref. start .. ] . as_ptr ( ) )
106
105
}
107
106
108
107
/// Returns the [`FuncHeader`] of the [`FuncBody`].
@@ -137,15 +136,14 @@ impl CodeMap {
137
136
#[ derive( Debug , Copy , Clone ) ]
138
137
pub struct InstructionPtr {
139
138
/// The pointer to the instruction.
140
- ptr : NonNull < Instruction > ,
139
+ ptr : * const Instruction ,
141
140
}
142
141
143
142
impl InstructionPtr {
144
143
/// Creates a new [`InstructionPtr`] for `instr`.
145
- pub fn new ( instr : & Instruction ) -> Self {
146
- Self {
147
- ptr : NonNull :: from ( instr) ,
148
- }
144
+ #[ inline]
145
+ pub fn new ( ptr : * const Instruction ) -> Self {
146
+ Self { ptr }
149
147
}
150
148
151
149
/// Offset the [`InstructionPtr`] by the given value.
@@ -157,8 +155,7 @@ impl InstructionPtr {
157
155
/// bounds of the instructions of the same compiled Wasm function.
158
156
#[ inline( always) ]
159
157
pub unsafe fn offset ( & mut self , by : isize ) {
160
- let new_ptr = & * self . ptr . as_ptr ( ) . offset ( by) ;
161
- self . ptr = NonNull :: from ( new_ptr) ;
158
+ self . ptr = self . ptr . offset ( by) ;
162
159
}
163
160
164
161
/// Returns a shared reference to the currently pointed at [`Instruction`].
@@ -170,6 +167,6 @@ impl InstructionPtr {
170
167
/// the boundaries of its associated compiled Wasm function.
171
168
#[ inline( always) ]
172
169
pub unsafe fn get ( & self ) -> & Instruction {
173
- self . ptr . as_ref ( )
170
+ & * self . ptr
174
171
}
175
172
}
0 commit comments