Skip to content

Commit 091fa96

Browse files
bors[bot]tczajka
andauthored
Merge #171
171: Shrink overallocated capacity if a number gets a lot smaller. r=cuviper a=tczajka 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. Co-authored-by: Tomek Czajka <tczajka@gmail.com>
2 parents 2fab5e4 + 35d6ad1 commit 091fa96

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
@@ -2616,6 +2616,9 @@ impl BigUint {
26162616
while let Some(&0) = self.data.last() {
26172617
self.data.pop();
26182618
}
2619+
if self.data.len() < self.data.capacity() / 4 {
2620+
self.data.shrink_to_fit();
2621+
}
26192622
}
26202623

26212624
/// Returns a normalized `BigUint`.

0 commit comments

Comments
 (0)