Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly improve try_into_range perf #172

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/bounds/userbounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,30 +213,32 @@ impl UserBoundsTrait<i32> for UserBounds {
/// );
/// ```
fn try_into_range(&self, parts_length: usize) -> Result<Range<usize>> {
let start: usize = match self.l {
let parts_length = parts_length as i32;

let start: i32 = match self.l {
Side::Continue => 0,
Side::Some(v) => {
if v.unsigned_abs() as usize > parts_length {
if v > parts_length || v < -parts_length {
bail!("Out of bounds: {}", v);
}
if v < 0 {
parts_length - v.unsigned_abs() as usize
parts_length + v
} else {
v as usize - 1
v - 1
}
}
};

let end: usize = match self.r {
let end: i32 = match self.r {
Side::Continue => parts_length,
Side::Some(v) => {
if v.unsigned_abs() as usize > parts_length {
if v > parts_length || v < -parts_length {
bail!("Out of bounds: {}", v);
}
if v < 0 {
parts_length - v.unsigned_abs() as usize + 1
parts_length + v + 1
} else {
v as usize
v
}
}
};
Expand All @@ -246,7 +248,10 @@ impl UserBoundsTrait<i32> for UserBounds {
bail!("Field left value cannot be greater than right value");
}

Ok(Range { start, end })
Ok(Range {
start: start as usize,
end: end as usize,
})
}

/// Transform a ranged bound into a list of one or more
Expand Down
Loading