Skip to content

Commit fa17d1c

Browse files
committed
Add comment to append_string for Standard
1 parent b4c1d66 commit fa17d1c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/distributions/other.rs

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ impl Distribution<char> for Standard {
9494
#[cfg(feature = "alloc")]
9595
impl DistString for Standard {
9696
fn append_string<R: Rng + ?Sized>(&self, rng: &mut R, s: &mut String, len: usize) {
97+
// A char is encoded with at most four bytes, thus this reservation is
98+
// guaranteed to be sufficient. We do not shrink_to_fit afterwards so
99+
// that repeated usage on the same `String` buffer does not reallocate.
97100
s.reserve(s.len() + 4 * len);
98101
s.extend(Distribution::<char>::sample_iter(self, rng).take(len));
99102
}

0 commit comments

Comments
 (0)