We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b4c1d66 commit fa17d1cCopy full SHA for fa17d1c
src/distributions/other.rs
@@ -94,6 +94,9 @@ impl Distribution<char> for Standard {
94
#[cfg(feature = "alloc")]
95
impl DistString for Standard {
96
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.
100
s.reserve(s.len() + 4 * len);
101
s.extend(Distribution::<char>::sample_iter(self, rng).take(len));
102
}
0 commit comments