diff --git a/src/lexical/bignum.rs b/src/lexical/bignum.rs index d419420..936cfa5 100644 --- a/src/lexical/bignum.rs +++ b/src/lexical/bignum.rs @@ -12,12 +12,9 @@ pub(crate) struct Bigint { impl Default for Bigint { fn default() -> Self { - // We want to repeated reallocations at smaller volumes. - let mut bigint = Bigint { - data: Vec::::default(), - }; - reserve(&mut bigint.data, 20); - bigint + Bigint { + data: Vec::with_capacity(20), + } } } diff --git a/src/lexical/math.rs b/src/lexical/math.rs index 2705541..deac78e 100644 --- a/src/lexical/math.rs +++ b/src/lexical/math.rs @@ -246,10 +246,7 @@ impl Hi64 for [u64] { /// warning. Smallvec is similarly licensed under an MIT/Apache dual license. /// /// [`smallvec`]: https://github.com/servo/rust-smallvec -fn insert_many(vec: &mut Vec, index: usize, iterable: Iter) -where - Iter: iter::IntoIterator, -{ +fn insert_many(vec: &mut Vec, index: usize, iterable: impl IntoIterator) { let iter = iterable.into_iter(); if index == vec.len() { return vec.extend(iter); @@ -275,7 +272,7 @@ where let mut cur = ptr.add(num_added); if num_added >= lower_size_bound { // Iterator provided more elements than the hint. Move trailing items again. - reserve(vec, 1); + vec.reserve(1); ptr = vec.as_mut_ptr().add(index); cur = ptr.add(num_added); ptr::copy(cur, cur.add(1), old_len - index); @@ -296,24 +293,6 @@ where } } -/// Resize vec to size. -#[inline] -fn resize(vec: &mut Vec, len: usize, value: Limb) { - vec.resize(len, value) -} - -/// Reserve vec capacity. -#[inline] -pub(crate) fn reserve(vec: &mut Vec, capacity: usize) { - vec.reserve(capacity) -} - -/// Reserve exact vec capacity. -#[inline] -fn reserve_exact(vec: &mut Vec, capacity: usize) { - vec.reserve_exact(capacity) -} - // SCALAR // ------ @@ -707,7 +686,7 @@ mod large { // that as the current range. If the effective y buffer is longer, need // to resize to that, + the start index. if y.len() > x.len() - xstart { - resize(x, y.len() + xstart, 0); + x.resize(y.len() + xstart, 0); } // Iteratively add elements from y to x. @@ -793,7 +772,7 @@ mod large { // frequent reallocations. Handle the first case to avoid a redundant // addition, since we know y.len() >= 1. let mut z: Vec = small::mul(x, y[0]); - resize(&mut z, x.len() + y.len(), 0); + z.resize(x.len() + y.len(), 0); // Handle the iterative cases. for (i, &yi) in y[1..].iter().enumerate() { @@ -839,9 +818,8 @@ mod large { // [z0, z1 - z2 - z0, z2] // z1 must be shifted m digits (2^(32m)) over. // z2 must be shifted 2*m digits (2^(64m)) over. - let mut result = Vec::::default(); let len = z0.len().max(m + z1.len()).max(2 * m + z2.len()); - reserve_exact(&mut result, len); + let mut result = Vec::::with_capacity(len); result.extend(z0.iter().cloned()); iadd_impl(&mut result, &z1, m); iadd_impl(&mut result, &z2, 2 * m); @@ -855,7 +833,7 @@ mod large { /// Assumes `y.len() >= x.len()`. fn karatsuba_uneven_mul(x: &[Limb], mut y: &[Limb]) -> Vec { let mut result = Vec::::default(); - resize(&mut result, x.len() + y.len(), 0); + result.resize(x.len() + y.len(), 0); // This effectively is like grade-school multiplication between // two numbers, except we're using splits on `y`, and the intermediate