skip to create list object

This commit is contained in:
Jeong YunWon
2021-11-29 15:05:19 +09:00
parent fe26754ad1
commit 65d9e2fa86

View File

@@ -10,6 +10,7 @@ use crate::{
bytesinner::bytes_to_hex,
function::{FuncArgs, IntoPyObject, OptionalArg},
protocol::{BufferDescriptor, BufferMethods, PyBuffer, PyMappingMethods, VecBuffer},
sequence::SequenceOp,
sliceable::wrap_index,
stdlib::pystruct::FormatSpec,
types::{AsBuffer, AsMapping, Comparable, Constructor, Hashable, PyComparisonOp},
@@ -629,16 +630,22 @@ impl PyMemoryView {
));
}
let tup;
let list;
let list_borrow;
let shape = match shape {
Either::A(tup) => {
let elements = tup.as_slice().iter().cloned().collect_vec();
vm.ctx.new_list(elements)
Either::A(shape) => {
tup = shape;
tup.as_slice()
}
Either::B(shape) => {
list = shape;
list_borrow = list.borrow_vec();
list_borrow.as_slice()
}
Either::B(list) => list,
};
let shape_vec = shape.borrow_vec();
let shape_ndim = shape_vec.len();
let shape_ndim = shape.len();
// TODO: MAX_NDIM
if self.desc.ndim() != 1 && shape_ndim != 1 {
return Err(
@@ -659,7 +666,7 @@ impl PyMemoryView {
let mut product_shape = itemsize;
let mut dim_descriptor = Vec::with_capacity(shape_ndim);
for x in shape_vec.iter() {
for x in shape.iter() {
let x = usize::try_from_borrowed_object(vm, x)?;
if x > isize::MAX as usize / product_shape {