1
+ use std:: ptr:: NonNull ;
2
+
1
3
use crate :: dimension:: { self , stride_offset} ;
2
4
use crate :: extension:: nonnull:: nonnull_debug_checked_from_ptr;
3
5
use crate :: imp_prelude:: * ;
@@ -11,16 +13,20 @@ where
11
13
///
12
14
/// Unsafe because caller is responsible for ensuring that the array will
13
15
/// meet all of the invariants of the `ArrayBase` type.
14
- #[ inline( always ) ]
15
- pub ( crate ) unsafe fn new_ ( ptr : * const A , dim : D , strides : D ) -> Self {
16
+ #[ inline]
17
+ pub ( crate ) unsafe fn new ( ptr : NonNull < A > , dim : D , strides : D ) -> Self {
16
18
RawArrayView {
17
19
data : RawViewRepr :: new ( ) ,
18
- ptr : nonnull_debug_checked_from_ptr ( ptr as * mut _ ) ,
20
+ ptr,
19
21
dim,
20
22
strides,
21
23
}
22
24
}
23
25
26
+ unsafe fn new_ ( ptr : * const A , dim : D , strides : D ) -> Self {
27
+ Self :: new ( nonnull_debug_checked_from_ptr ( ptr as * mut A ) , dim, strides)
28
+ }
29
+
24
30
/// Create an `RawArrayView<A, D>` from shape information and a raw pointer
25
31
/// to the elements.
26
32
///
76
82
/// ensure that all of the data is valid and choose the correct lifetime.
77
83
#[ inline]
78
84
pub unsafe fn deref_into_view < ' a > ( self ) -> ArrayView < ' a , A , D > {
79
- ArrayView :: new_ ( self . ptr . as_ptr ( ) , self . dim , self . strides )
85
+ ArrayView :: new ( self . ptr , self . dim , self . strides )
80
86
}
81
87
82
88
/// Split the array view along `axis` and return one array pointer strictly
@@ -115,16 +121,20 @@ where
115
121
///
116
122
/// Unsafe because caller is responsible for ensuring that the array will
117
123
/// meet all of the invariants of the `ArrayBase` type.
118
- #[ inline( always ) ]
119
- pub ( crate ) unsafe fn new_ ( ptr : * mut A , dim : D , strides : D ) -> Self {
124
+ #[ inline]
125
+ pub ( crate ) unsafe fn new ( ptr : NonNull < A > , dim : D , strides : D ) -> Self {
120
126
RawArrayViewMut {
121
127
data : RawViewRepr :: new ( ) ,
122
- ptr : nonnull_debug_checked_from_ptr ( ptr ) ,
128
+ ptr,
123
129
dim,
124
130
strides,
125
131
}
126
132
}
127
133
134
+ unsafe fn new_ ( ptr : * mut A , dim : D , strides : D ) -> Self {
135
+ Self :: new ( nonnull_debug_checked_from_ptr ( ptr) , dim, strides)
136
+ }
137
+
128
138
/// Create an `RawArrayViewMut<A, D>` from shape information and a raw
129
139
/// pointer to the elements.
130
140
///
@@ -176,7 +186,7 @@ where
176
186
/// Converts to a non-mutable `RawArrayView`.
177
187
#[ inline]
178
188
pub ( crate ) fn into_raw_view ( self ) -> RawArrayView < A , D > {
179
- unsafe { RawArrayView :: new_ ( self . ptr . as_ptr ( ) , self . dim , self . strides ) }
189
+ unsafe { RawArrayView :: new ( self . ptr , self . dim , self . strides ) }
180
190
}
181
191
182
192
/// Converts to a read-only view of the array.
@@ -186,7 +196,7 @@ where
186
196
/// ensure that all of the data is valid and choose the correct lifetime.
187
197
#[ inline]
188
198
pub unsafe fn deref_into_view < ' a > ( self ) -> ArrayView < ' a , A , D > {
189
- ArrayView :: new_ ( self . ptr . as_ptr ( ) , self . dim , self . strides )
199
+ ArrayView :: new ( self . ptr , self . dim , self . strides )
190
200
}
191
201
192
202
/// Converts to a mutable view of the array.
@@ -196,7 +206,7 @@ where
196
206
/// ensure that all of the data is valid and choose the correct lifetime.
197
207
#[ inline]
198
208
pub unsafe fn deref_into_view_mut < ' a > ( self ) -> ArrayViewMut < ' a , A , D > {
199
- ArrayViewMut :: new_ ( self . ptr . as_ptr ( ) , self . dim , self . strides )
209
+ ArrayViewMut :: new ( self . ptr , self . dim , self . strides )
200
210
}
201
211
202
212
/// Split the array view along `axis` and return one array pointer strictly
@@ -207,8 +217,8 @@ where
207
217
let ( left, right) = self . into_raw_view ( ) . split_at ( axis, index) ;
208
218
unsafe {
209
219
(
210
- Self :: new_ ( left. ptr . as_ptr ( ) , left. dim , left. strides ) ,
211
- Self :: new_ ( right. ptr . as_ptr ( ) , right. dim , right. strides ) ,
220
+ Self :: new ( left. ptr , left. dim , left. strides ) ,
221
+ Self :: new ( right. ptr , right. dim , right. strides ) ,
212
222
)
213
223
}
214
224
}
0 commit comments