Skip to content

Commit 35d6ad1

Browse files
committed
Shrink overallocated capacity if a number gets a lot smaller.
If a number gets below 1/4 of capacity, shrink_to_fit. Since Vec grows by 2, this amortizes well for any sequence of sizes.
1 parent 7562ab2 commit 35d6ad1

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/biguint.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,6 +2617,9 @@ impl BigUint {
26172617
while let Some(&0) = self.data.last() {
26182618
self.data.pop();
26192619
}
2620+
if self.data.len() < self.data.capacity() / 4 {
2621+
self.data.shrink_to_fit();
2622+
}
26202623
}
26212624

26222625
/// Returns a normalized `BigUint`.

0 commit comments

Comments
 (0)