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 dbabbb7 commit c0991aeCopy full SHA for c0991ae
alloc/src/vec.rs
@@ -622,7 +622,10 @@ impl<T> Vec<T> {
622
/// ```
623
#[stable(feature = "rust1", since = "1.0.0")]
624
pub fn shrink_to_fit(&mut self) {
625
- if self.capacity() != self.len {
+ // The capacity is never less than the length, and there's nothing to do when
626
+ // they are equal, so we can avoid the panic case in `RawVec::shrink_to_fit`
627
+ // by only calling it with a greater capacity.
628
+ if self.capacity() > self.len {
629
self.buf.shrink_to_fit(self.len);
630
}
631
0 commit comments