Skip to content

Commit

Permalink
🐎 Avoid unnecessary memory allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanTsune committed Aug 21, 2023
1 parent dbda51d commit 252a19b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ impl FromStr for SliceRange {
}
.map_err(|e| e.to_string())
}
let ptn = s.split(':').collect::<Vec<_>>();
let mut ptn = s.split(':');
Ok(Self {
start: parse_or(
ptn.first()
ptn.next()
.ok_or_else(|| String::from("range start must be needed"))?,
0,
)?,
end: parse_or(
ptn.get(1)
ptn.next()
.ok_or_else(|| String::from("range end must be needed"))?,
usize::MAX,
)?,
step: match ptn.get(2) {
step: match ptn.next() {
Some(step) => Some(parse_or(step, unsafe { NonZeroUsize::new_unchecked(1) })?),
None => None,
},
Expand Down

0 comments on commit 252a19b

Please sign in to comment.