about summary refs log tree commit diff
path: root/src/librustc_data_structures
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2016-10-18 08:23:09 +1100
committerNicholas Nethercote <nnethercote@mozilla.com>2016-11-22 10:02:04 +1100
commitf72685f2ffd1e79c2d4e099770490d4cf00795fa (patch)
treec9f17d7192af2ff033dce2e4ce7ce6837fe9a604 /src/librustc_data_structures
parent80a95e34fe32ca86982607a85e9c5714eb6262d9 (diff)
downloadrust-f72685f2ffd1e79c2d4e099770490d4cf00795fa.tar.gz
rust-f72685f2ffd1e79c2d4e099770490d4cf00795fa.zip
Use SmallVec for TypeWalker's stack.
The change also adds the missing `SmallVec::truncate` method.
Diffstat (limited to 'src/librustc_data_structures')
-rw-r--r--src/librustc_data_structures/small_vec.rs12
1 files changed, 12 insertions, 0 deletions
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<A: Array> SmallVec<A> {
             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<A: Array> Deref for SmallVec<A> {