sequence comparison uses impl SimpleSeq rather than dyn SimpleSeq

This commit is contained in:
Jeong YunWon
2020-01-02 23:52:54 +09:00
parent 6f313c191e
commit 50ff5e89f9
2 changed files with 24 additions and 10 deletions

View File

@@ -277,8 +277,8 @@ impl SimpleSeq for std::collections::VecDeque<PyObjectRef> {
pub fn seq_equal(
vm: &VirtualMachine,
zelf: &dyn SimpleSeq,
other: &dyn SimpleSeq,
zelf: &impl SimpleSeq,
other: &impl SimpleSeq,
) -> PyResult<bool> {
if zelf.len() == other.len() {
for (a, b) in Iterator::zip(zelf.iter(), other.iter()) {
@@ -295,7 +295,11 @@ pub fn seq_equal(
}
}
pub fn seq_lt(vm: &VirtualMachine, zelf: &dyn SimpleSeq, other: &dyn SimpleSeq) -> PyResult<bool> {
pub fn seq_lt(
vm: &VirtualMachine,
zelf: &impl SimpleSeq,
other: &impl SimpleSeq,
) -> PyResult<bool> {
for (a, b) in Iterator::zip(zelf.iter(), other.iter()) {
if let Some(v) = vm.bool_seq_lt(a.clone(), b.clone())? {
return Ok(v);
@@ -304,7 +308,11 @@ pub fn seq_lt(vm: &VirtualMachine, zelf: &dyn SimpleSeq, other: &dyn SimpleSeq)
Ok(zelf.len() < other.len())
}
pub fn seq_gt(vm: &VirtualMachine, zelf: &dyn SimpleSeq, other: &dyn SimpleSeq) -> PyResult<bool> {
pub fn seq_gt(
vm: &VirtualMachine,
zelf: &impl SimpleSeq,
other: &impl SimpleSeq,
) -> PyResult<bool> {
for (a, b) in Iterator::zip(zelf.iter(), other.iter()) {
if let Some(v) = vm.bool_seq_gt(a.clone(), b.clone())? {
return Ok(v);
@@ -313,7 +321,11 @@ pub fn seq_gt(vm: &VirtualMachine, zelf: &dyn SimpleSeq, other: &dyn SimpleSeq)
Ok(zelf.len() > other.len())
}
pub fn seq_ge(vm: &VirtualMachine, zelf: &dyn SimpleSeq, other: &dyn SimpleSeq) -> PyResult<bool> {
pub fn seq_ge(
vm: &VirtualMachine,
zelf: &impl SimpleSeq,
other: &impl SimpleSeq,
) -> PyResult<bool> {
for (a, b) in Iterator::zip(zelf.iter(), other.iter()) {
if let Some(v) = vm.bool_seq_gt(a.clone(), b.clone())? {
return Ok(v);
@@ -323,7 +335,11 @@ pub fn seq_ge(vm: &VirtualMachine, zelf: &dyn SimpleSeq, other: &dyn SimpleSeq)
Ok(zelf.len() >= other.len())
}
pub fn seq_le(vm: &VirtualMachine, zelf: &dyn SimpleSeq, other: &dyn SimpleSeq) -> PyResult<bool> {
pub fn seq_le(
vm: &VirtualMachine,
zelf: &impl SimpleSeq,
other: &impl SimpleSeq,
) -> PyResult<bool> {
for (a, b) in Iterator::zip(zelf.iter(), other.iter()) {
if let Some(v) = vm.bool_seq_lt(a.clone(), b.clone())? {
return Ok(v);
@@ -365,7 +381,7 @@ impl<'a> Iterator for SeqMul<'a> {
}
impl ExactSizeIterator for SeqMul<'_> {}
pub fn seq_mul(seq: &dyn SimpleSeq, repetitions: isize) -> SeqMul {
pub fn seq_mul(seq: &impl SimpleSeq, repetitions: isize) -> SeqMul {
SeqMul {
seq,
repetitions: repetitions.max(0) as usize,

View File

@@ -189,9 +189,7 @@ impl PyTuple {
#[pymethod(name = "__mul__")]
fn mul(&self, counter: isize, vm: &VirtualMachine) -> PyObjectRef {
let new_elements = seq_mul(&self.as_slice(), counter)
.cloned()
.collect();
let new_elements = seq_mul(&self.as_slice(), counter).cloned().collect();
vm.ctx.new_tuple(new_elements)
}