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 10, 2021
1 parent fa17d1c commit 81f1af8
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/distributions/other.rs
Original file line number Diff line number Diff line change
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,6 @@ 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.extend(self.sample_iter(rng).take(len));
}
}
Expand Down

0 comments on commit 81f1af8

Please # to comment.