@@ -307,6 +307,10 @@ pub const ARRAY_FORMAT_VERSION: u8 = 1u8;
307
307
308
308
// use "raw" form instead of type aliases here so that they show up in docs
309
309
/// Implementation of `ArrayView::from(&S)` where `S` is a slice or sliceable.
310
+ ///
311
+ /// **Panics** if the length of the slice overflows `isize`. (This can only
312
+ /// occur if `A` is zero-sized, because slices cannot contain more than
313
+ /// `isize::MAX` number of bytes.)
310
314
impl < ' a , A , Slice : ?Sized > From < & ' a Slice > for ArrayView < ' a , A , Ix1 >
311
315
where
312
316
Slice : AsRef < [ A ] > ,
@@ -315,14 +319,7 @@ where
315
319
///
316
320
/// **Panics** if the slice length is greater than `isize::MAX`.
317
321
fn from ( slice : & ' a Slice ) -> Self {
318
- let xs = slice. as_ref ( ) ;
319
- if mem:: size_of :: < A > ( ) == 0 {
320
- assert ! (
321
- xs. len( ) <= :: std:: isize :: MAX as usize ,
322
- "Slice length must fit in `isize`." ,
323
- ) ;
324
- }
325
- unsafe { Self :: from_shape_ptr ( xs. len ( ) , xs. as_ptr ( ) ) }
322
+ aview1 ( slice. as_ref ( ) )
326
323
}
327
324
}
328
325
@@ -334,25 +331,7 @@ where
334
331
impl < ' a , A , const N : usize > From < & ' a [ [ A ; N ] ] > for ArrayView < ' a , A , Ix2 > {
335
332
/// Create a two-dimensional read-only array view of the data in `slice`
336
333
fn from ( xs : & ' a [ [ A ; N ] ] ) -> Self {
337
- let cols = N ;
338
- let rows = xs. len ( ) ;
339
- let dim = Ix2 ( rows, cols) ;
340
- if size_of :: < A > ( ) == 0 {
341
- dimension:: size_of_shape_checked ( & dim)
342
- . expect ( "Product of non-zero axis lengths must not overflow isize." ) ;
343
- } else if N == 0 {
344
- assert ! (
345
- xs. len( ) <= isize :: MAX as usize ,
346
- "Product of non-zero axis lengths must not overflow isize." ,
347
- ) ;
348
- }
349
-
350
- // `cols * rows` is guaranteed to fit in `isize` because we checked that it fits in
351
- // `isize::MAX`
352
- unsafe {
353
- let data = slice:: from_raw_parts ( xs. as_ptr ( ) as * const A , cols * rows) ;
354
- ArrayView :: from_shape_ptr ( dim, data. as_ptr ( ) )
355
- }
334
+ aview2 ( xs)
356
335
}
357
336
}
358
337
0 commit comments