Skip to content

Commit 81f1af8

Browse files
committed
Correct usage of reserve
1 parent fa17d1c commit 81f1af8

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/distributions/other.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl DistString for Standard {
9797
// A char is encoded with at most four bytes, thus this reservation is
9898
// guaranteed to be sufficient. We do not shrink_to_fit afterwards so
9999
// that repeated usage on the same `String` buffer does not reallocate.
100-
s.reserve(s.len() + 4 * len);
100+
s.reserve(4 * len);
101101
s.extend(Distribution::<char>::sample_iter(self, rng).take(len));
102102
}
103103
}
@@ -126,7 +126,6 @@ impl DistString for Alphanumeric {
126126
fn append_string<R: Rng + ?Sized>(&self, rng: &mut R, string: &mut String, len: usize) {
127127
unsafe {
128128
let v = string.as_mut_vec();
129-
v.reserve(v.len() + len);
130129
v.extend(self.sample_iter(rng).take(len));
131130
}
132131
}

0 commit comments

Comments
 (0)