From f72685f2ffd1e79c2d4e099770490d4cf00795fa Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 18 Oct 2016 08:23:09 +1100 Subject: Use SmallVec for TypeWalker's stack. The change also adds the missing `SmallVec::truncate` method. --- src/librustc_data_structures/small_vec.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/librustc_data_structures/small_vec.rs') diff --git a/src/librustc_data_structures/small_vec.rs b/src/librustc_data_structures/small_vec.rs index 565a3c443a3..4e2b3786021 100644 --- a/src/librustc_data_structures/small_vec.rs +++ b/src/librustc_data_structures/small_vec.rs @@ -130,6 +130,18 @@ impl SmallVec { self.set_len(len + 1); } } + + pub fn truncate(&mut self, len: usize) { + unsafe { + while len < self.len() { + // Decrement len before the drop_in_place(), so a panic on Drop + // doesn't re-drop the just-failed value. + let newlen = self.len() - 1; + self.set_len(newlen); + ::std::ptr::drop_in_place(self.get_unchecked_mut(newlen)); + } + } + } } impl Deref for SmallVec { -- cgit 1.4.1-3-g733a5