Skip to content

Commit

Permalink
Merge #171
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bors[bot] and tczajka authored Oct 30, 2020
2 parents 2fab5e4 + 35d6ad1 commit 091fa96
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/biguint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2616,6 +2616,9 @@ impl BigUint {
while let Some(&0) = self.data.last() {
self.data.pop();
}
if self.data.len() < self.data.capacity() / 4 {
self.data.shrink_to_fit();
}
}

/// Returns a normalized `BigUint`.
Expand Down

0 comments on commit 091fa96

Please sign in to comment.