From fa17d1c1a292e6bb95743885c839a8a902e89e81 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Tue, 8 Jun 2021 08:16:07 +0100 Subject: [PATCH] Add comment to append_string for Standard --- src/distributions/other.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/distributions/other.rs b/src/distributions/other.rs index 2e932703..7ce95ec3 100644 --- a/src/distributions/other.rs +++ b/src/distributions/other.rs @@ -94,6 +94,9 @@ impl Distribution for Standard { #[cfg(feature = "alloc")] impl DistString for Standard { fn append_string(&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::::sample_iter(self, rng).take(len)); }