Add comment to append_string for Standard

This commit is contained in:
Diggory Hardy
2021-06-08 08:16:07 +01:00
parent b4c1d66409
commit fa17d1c1a2
+3
View File
@@ -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));
}