Skip to content

Commit

Permalink
Don't worry about skipping checks with an overallocated buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexhuszagh committed Sep 15, 2024
1 parent 89f6b67 commit 559a1cf
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions lexical-parse-float/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,7 @@ impl<const SIZE: usize> StackVec<SIZE> {
pub fn from_u16(x: u16) -> Self {
let mut vec = Self::new();
assert!(1 <= vec.capacity());
// SAFETY: safe since we can always add 1 item.
unsafe { vec.push_unchecked(x as Limb) };
_ = vec.try_push(x as Limb);
vec.normalize();
vec
}
Expand All @@ -598,8 +597,7 @@ impl<const SIZE: usize> StackVec<SIZE> {
let mut vec = Self::new();
debug_assert!(1 <= vec.capacity());
assert!(1 <= SIZE);
// SAFETY: safe since we can always add 1 item (validated in the asset).
unsafe { vec.push_unchecked(x as Limb) };
_ = vec.try_push(x as Limb);
vec.normalize();
vec
}
Expand All @@ -611,14 +609,10 @@ impl<const SIZE: usize> StackVec<SIZE> {
debug_assert!(2 <= vec.capacity());
assert!(2 <= SIZE);
if LIMB_BITS == 32 {
// SAFETY: safe since we can always add 2 items (validated in the asset).
unsafe {
vec.push_unchecked(x as Limb);
vec.push_unchecked((x >> 32) as Limb);
}
_ = vec.try_push(x as Limb);
_ = vec.try_push((x >> 32) as Limb);
} else {
// SAFETY: safe since we can always add 1 item.
unsafe { vec.push_unchecked(x as Limb) };
_ = vec.try_push(x as Limb);
}
vec.normalize();
vec
Expand Down

0 comments on commit 559a1cf

Please sign in to comment.