Skip to content

Commit

Permalink
Fix nonsense 'abs' function
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelishman committed Jun 26, 2024
1 parent b1277d2 commit 6083896
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions crates/circuit/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ impl<'py> FromPyObject<'py> for PySequenceIndex<'py> {
impl<'py> PySequenceIndex<'py> {
/// Specialize this index to a collection of the given `len`, returning a Rust-native type.
pub fn with_len(&self, len: usize) -> Result<SequenceIndex, PySequenceIndexError> {
let abs = |index: isize| -> Result<usize, PySequenceIndexError> {
if index >= 0 {
Ok(index as usize)
} else if index == ::std::isize::MIN {
Err(PySequenceIndexError::OutOfRange)
} else {
Ok(-index as usize)
}
};
match self {
PySequenceIndex::Int(index) => {
let index = if *index >= 0 {
Expand All @@ -62,7 +53,7 @@ impl<'py> PySequenceIndex<'py> {
}
index
} else {
len.checked_sub(abs(*index)?)
len.checked_sub(index.unsigned_abs())
.ok_or(PySequenceIndexError::OutOfRange)?
};
Ok(SequenceIndex::Int(index))
Expand All @@ -83,7 +74,7 @@ impl<'py> PySequenceIndex<'py> {
start: (indices.start >= 0).then_some(indices.start as usize),
// `indices.stop` can be negative if the 0 index should be output.
stop: (indices.stop >= 0).then_some(indices.stop as usize),
step: abs(indices.step)?,
step: indices.step.unsigned_abs(),
})
}
}
Expand Down

0 comments on commit 6083896

Please sign in to comment.