Skip to content

Commit

Permalink
Auto merge of #28531 - whitequark:patch-1, r=Gankro
Browse files Browse the repository at this point in the history
With -O2, LLVM's inliner can remove this code, but this does not happen
with -O1 and lower. As a result, dropping Vec<u8> was linear with length,
resulting in abysmal performance for large buffers.

See issue #24280.
  • Loading branch information
bors committed Sep 21, 2015
2 parents 0a96756 + 77f5da7 commit 547fd5c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use alloc::heap::EMPTY;
use core::cmp::Ordering;
use core::fmt;
use core::hash::{self, Hash};
use core::intrinsics::{arith_offset, assume, drop_in_place};
use core::intrinsics::{arith_offset, assume, drop_in_place, needs_drop};
use core::iter::FromIterator;
use core::mem;
use core::ops::{Index, IndexMut, Deref};
Expand Down Expand Up @@ -1322,8 +1322,14 @@ impl<T> Drop for Vec<T> {
// OK because exactly when this stops being a valid assumption, we
// don't need unsafe_no_drop_flag shenanigans anymore.
if self.buf.unsafe_no_drop_flag_needs_drop() {
for x in self.iter_mut() {
unsafe { drop_in_place(x); }
unsafe {
// The branch on needs_drop() is an -O1 performance optimization.
// Without the branch, dropping Vec<u8> takes linear time.
if needs_drop::<T>() {
for x in self.iter_mut() {
drop_in_place(x);
}
}
}
}
// RawVec handles deallocation
Expand Down

0 comments on commit 547fd5c

Please sign in to comment.