Skip to content

Commit

Permalink
Correct usage of reserve
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Jun 9, 2021
1 parent e87c67d commit 60e3557
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/distributions/other.rs
Expand Up @@ -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::<char>::sample_iter(self, rng).take(len));
}
}
Expand Down Expand Up @@ -126,7 +126,7 @@ impl DistString for Alphanumeric {
fn append_string<R: Rng + ?Sized>(&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));
}
}
Expand Down

0 comments on commit 60e3557

Please sign in to comment.