Remove PySliceRef

This commit is contained in:
Jeong YunWon
2021-10-13 02:50:51 +09:00
parent 997f85ff54
commit c05e8eb48c
6 changed files with 19 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
use super::{PositionIterInternal, PyGenericAlias, PySliceRef, PyTupleRef, PyTypeRef};
use super::{PositionIterInternal, PyGenericAlias, PySlice, PyTupleRef, PyTypeRef};
use crate::common::lock::{
PyMappedRwLockReadGuard, PyMutex, PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard,
};
@@ -210,7 +210,12 @@ impl PyList {
}
}
fn setslice(&self, slice: PySliceRef, sec: ArgIterable, vm: &VirtualMachine) -> PyResult<()> {
fn setslice(
&self,
slice: PyRef<PySlice>,
sec: ArgIterable,
vm: &VirtualMachine,
) -> PyResult<()> {
let items: Result<Vec<PyObjectRef>, _> = sec.iter(vm)?.collect();
let items = items?;
let slice = slice.to_saturated(vm)?;
@@ -492,7 +497,7 @@ impl PyList {
removed.map(drop)
}
fn delslice(&self, slice: PySliceRef, vm: &VirtualMachine) -> PyResult<()> {
fn delslice(&self, slice: PyRef<PySlice>, vm: &VirtualMachine) -> PyResult<()> {
let slice = slice.to_saturated(vm)?;
self.borrow_vec_mut().delete_slice(vm, slice)
}

View File

@@ -1,4 +1,4 @@
use super::{PyBytes, PyBytesRef, PyList, PyListRef, PySliceRef, PyStr, PyStrRef, PyTypeRef};
use super::{PyBytes, PyBytesRef, PyList, PyListRef, PySlice, PyStr, PyStrRef, PyTypeRef};
use crate::common::{
borrow::{BorrowedValue, BorrowedValueMut},
hash::PyHash,
@@ -250,7 +250,7 @@ impl PyMemoryView {
})
}
fn getitem_by_slice(zelf: PyRef<Self>, slice: PySliceRef, vm: &VirtualMachine) -> PyResult {
fn getitem_by_slice(zelf: PyRef<Self>, slice: PyRef<PySlice>, vm: &VirtualMachine) -> PyResult {
// slicing a memoryview return a new memoryview
let len = zelf.buffer.options.len;
let (range, step, is_negative_step) =
@@ -368,7 +368,7 @@ impl PyMemoryView {
fn setitem_by_slice(
zelf: PyRef<Self>,
slice: PySliceRef,
slice: PyRef<PySlice>,
items: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<()> {

View File

@@ -1,4 +1,6 @@
//! This package contains the python basic/builtin types
//! 7 common PyRef type aliases are exposed - PyBytesRef, PyDictRef, PyIntRef, PyListRef, PyStrRef, PyTypeRef, PyTupleRef
//! Do not add more PyRef type aliases. They will be rare enough to use directly PyRef<T>.
pub(crate) mod asyncgenerator;
pub use asyncgenerator::PyAsyncGen;
@@ -67,7 +69,7 @@ pub use set::{PyFrozenSet, PySet};
pub(crate) mod singletons;
pub use singletons::{PyNone, PyNotImplemented};
pub(crate) mod slice;
pub use slice::{PyEllipsis, PySlice, PySliceRef};
pub use slice::{PyEllipsis, PySlice};
pub(crate) mod staticmethod;
pub use staticmethod::PyStaticMethod;
pub(crate) mod traceback;

View File

@@ -1,4 +1,4 @@
use super::{PyInt, PyIntRef, PySlice, PySliceRef, PyTupleRef, PyTypeRef};
use super::{PyInt, PyIntRef, PySlice, PyTupleRef, PyTypeRef};
use crate::builtins::builtins_iter;
use crate::common::hash::PyHash;
use crate::{
@@ -664,7 +664,7 @@ fn range_state(length: &BigInt, state: PyObjectRef, vm: &VirtualMachine) -> PyRe
pub enum RangeIndex {
Int(PyIntRef),
Slice(PySliceRef),
Slice(PyRef<PySlice>),
}
impl TryFromObject for RangeIndex {

View File

@@ -24,8 +24,6 @@ impl PyValue for PySlice {
}
}
pub type PySliceRef = PyRef<PySlice>;
#[pyimpl(with(Hashable, Comparable))]
impl PySlice {
#[pyproperty]

View File

@@ -3,11 +3,11 @@ use std::ops::Range;
use crate::builtins::int::PyInt;
// export through slicable module, not slice.
use crate::builtins::slice::PySlice;
pub use crate::builtins::slice::{saturate_index, SaturatedSlice};
use crate::builtins::slice::{PySlice, PySliceRef};
use crate::utils::Either;
use crate::VirtualMachine;
use crate::{PyObjectRef, PyResult, TypeProtocol};
use crate::{PyObjectRef, PyRef, PyResult, TypeProtocol};
pub trait PySliceableSequenceMut {
type Item: Clone;
@@ -332,7 +332,7 @@ impl<T: Clone> PySliceableSequence for [T] {
pub enum SequenceIndex {
Int(isize),
Slice(PySliceRef),
Slice(PyRef<PySlice>),
}
impl SequenceIndex {