Skip to content

Commit

Permalink
Add comment to append_string for Standard
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Jun 10, 2021
1 parent b4c1d66 commit fa17d1c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/distributions/other.rs
Expand Up @@ -94,6 +94,9 @@ impl Distribution<char> for Standard {
#[cfg(feature = "alloc")]
impl DistString for Standard {
fn append_string<R: Rng + ?Sized>(&self, rng: &mut R, s: &mut String, len: usize) {
// 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.extend(Distribution::<char>::sample_iter(self, rng).take(len));
}
Expand Down

0 comments on commit fa17d1c

Please sign in to comment.