Skip to content

Commit e852ffe

Browse files
committed
Make slice.stop not an option
1 parent e0f7fbb commit e852ffe

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

vm/src/frame.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,10 @@ impl Frame {
407407
} else {
408408
None
409409
};
410-
let stop = Some(self.pop_value());
411-
let start = Some(self.pop_value());
410+
let stop = self.pop_value();
411+
let start = self.pop_value();
412412

413-
let obj = PySlice { start, stop, step }.into_ref(vm);
413+
let obj = PySlice { start: Some(start), stop, step }.into_ref(vm);
414414
self.push_value(obj.into_object());
415415
Ok(None)
416416
}

vm/src/obj/objslice.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use num_bigint::BigInt;
99
#[derive(Debug)]
1010
pub struct PySlice {
1111
pub start: Option<PyObjectRef>,
12-
pub stop: Option<PyObjectRef>,
12+
pub stop: PyObjectRef,
1313
pub step: Option<PyObjectRef>,
1414
}
1515

@@ -30,7 +30,7 @@ fn slice_new(cls: PyClassRef, args: PyFuncArgs, vm: &VirtualMachine) -> PyResult
3030
let stop = args.bind(vm)?;
3131
PySlice {
3232
start: None,
33-
stop: Some(stop),
33+
stop,
3434
step: None,
3535
}
3636
}
@@ -39,7 +39,7 @@ fn slice_new(cls: PyClassRef, args: PyFuncArgs, vm: &VirtualMachine) -> PyResult
3939
args.bind(vm)?;
4040
PySlice {
4141
start: Some(start),
42-
stop: Some(stop),
42+
stop,
4343
step: step.into_option(),
4444
}
4545
}
@@ -60,8 +60,8 @@ impl PySliceRef {
6060
get_property_value(vm, &self.start)
6161
}
6262

63-
fn stop(self, vm: &VirtualMachine) -> PyObjectRef {
64-
get_property_value(vm, &self.stop)
63+
fn stop(self, _vm: &VirtualMachine) -> PyObjectRef {
64+
self.stop.clone()
6565
}
6666

6767
fn step(self, vm: &VirtualMachine) -> PyObjectRef {
@@ -77,11 +77,7 @@ impl PySliceRef {
7777
}
7878

7979
pub fn stop_index(&self, vm: &VirtualMachine) -> PyResult<Option<BigInt>> {
80-
if let Some(obj) = &self.stop {
81-
to_index_value(vm, obj)
82-
} else {
83-
Ok(None)
84-
}
80+
to_index_value(vm, &self.stop)
8581
}
8682

8783
pub fn step_index(&self, vm: &VirtualMachine) -> PyResult<Option<BigInt>> {

0 commit comments

Comments
 (0)