1+ use std:: ptr:: NonNull ;
2+
13use crate :: dimension:: { self , stride_offset} ;
24use crate :: extension:: nonnull:: nonnull_debug_checked_from_ptr;
35use crate :: imp_prelude:: * ;
@@ -11,16 +13,20 @@ where
1113 ///
1214 /// Unsafe because caller is responsible for ensuring that the array will
1315 /// 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 {
1618 RawArrayView {
1719 data : RawViewRepr :: new ( ) ,
18- ptr : nonnull_debug_checked_from_ptr ( ptr as * mut _ ) ,
20+ ptr,
1921 dim,
2022 strides,
2123 }
2224 }
2325
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+
2430 /// Create an `RawArrayView<A, D>` from shape information and a raw pointer
2531 /// to the elements.
2632 ///
7682 /// ensure that all of the data is valid and choose the correct lifetime.
7783 #[ inline]
7884 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 )
8086 }
8187
8288 /// Split the array view along `axis` and return one array pointer strictly
@@ -115,16 +121,20 @@ where
115121 ///
116122 /// Unsafe because caller is responsible for ensuring that the array will
117123 /// 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 {
120126 RawArrayViewMut {
121127 data : RawViewRepr :: new ( ) ,
122- ptr : nonnull_debug_checked_from_ptr ( ptr ) ,
128+ ptr,
123129 dim,
124130 strides,
125131 }
126132 }
127133
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+
128138 /// Create an `RawArrayViewMut<A, D>` from shape information and a raw
129139 /// pointer to the elements.
130140 ///
@@ -176,7 +186,7 @@ where
176186 /// Converts to a non-mutable `RawArrayView`.
177187 #[ inline]
178188 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 ) }
180190 }
181191
182192 /// Converts to a read-only view of the array.
@@ -186,7 +196,7 @@ where
186196 /// ensure that all of the data is valid and choose the correct lifetime.
187197 #[ inline]
188198 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 )
190200 }
191201
192202 /// Converts to a mutable view of the array.
@@ -196,7 +206,7 @@ where
196206 /// ensure that all of the data is valid and choose the correct lifetime.
197207 #[ inline]
198208 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 )
200210 }
201211
202212 /// Split the array view along `axis` and return one array pointer strictly
@@ -207,8 +217,8 @@ where
207217 let ( left, right) = self . into_raw_view ( ) . split_at ( axis, index) ;
208218 unsafe {
209219 (
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 ) ,
212222 )
213223 }
214224 }
0 commit comments