From 60e3557ba0d2ce59a21ccc01660e29fec90b95a0 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Wed, 9 Jun 2021 08:52:28 +0100 Subject: [PATCH] Correct usage of reserve --- src/distributions/other.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/distributions/other.rs b/src/distributions/other.rs index 7ce95ec342e..4bbd7cf2fd9 100644 --- a/src/distributions/other.rs +++ b/src/distributions/other.rs @@ -97,7 +97,7 @@ impl DistString for Standard { // A char is encoded with at most four bytes, thus this reservation is // guaranteed to be sufficient. We do not shrink_to_fit afterwards so // that repeated usage on the same `String` buffer does not reallocate. - s.reserve(s.len() + 4 * len); + s.reserve(4 * len); s.extend(Distribution::::sample_iter(self, rng).take(len)); } } @@ -126,7 +126,7 @@ impl DistString for Alphanumeric { fn append_string(&self, rng: &mut R, string: &mut String, len: usize) { unsafe { let v = string.as_mut_vec(); - v.reserve(v.len() + len); + v.reserve(len); v.extend(self.sample_iter(rng).take(len)); } }