about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2018-08-13 17:09:13 -0700
committerDavid Tolnay <dtolnay@gmail.com>2018-08-13 17:09:13 -0700
commit69b9c23b3858dc87ceb6629b7640d5f579b8ed79 (patch)
tree02449789d0ddc4fa0c4dd296c5caa5561c1ea96a /src/libsyntax
parent2fa1da991945b2c2d3b36241492f7e8280869fd0 (diff)
downloadrust-69b9c23b3858dc87ceb6629b7640d5f579b8ed79.tar.gz
rust-69b9c23b3858dc87ceb6629b7640d5f579b8ed79.zip
Address review of RcVec
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/util/rc_vec.rs15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/libsyntax/util/rc_vec.rs b/src/libsyntax/util/rc_vec.rs
index b2785d7143d..99fbce1ad91 100644
--- a/src/libsyntax/util/rc_vec.rs
+++ b/src/libsyntax/util/rc_vec.rs
@@ -27,12 +27,7 @@ impl<T> RcVec<T> {
         // to hold the initial elements. Callers that anticipate needing to
         // extend the vector may prefer RcVec::new_preserving_capacity.
         vec.shrink_to_fit();
-
-        RcVec {
-            offset: 0,
-            len: vec.len() as u32,
-            data: Lrc::new(vec),
-        }
+        Self::new_preserving_capacity(vec)
     }
 
     pub fn new_preserving_capacity(vec: Vec<T>) -> Self {
@@ -59,10 +54,10 @@ impl<T> RcVec<T> {
             Ok(mut vec) => {
                 // Drop any elements after our view of the data.
                 vec.truncate(self.offset as usize + self.len as usize);
-                // Drop any elements before our view of the data.
-                if self.offset != 0 {
-                    vec.drain(..self.offset as usize);
-                }
+                // Drop any elements before our view of the data. Do this after
+                // the `truncate` so that elements past the end of our view do
+                // not need to be copied around.
+                vec.drain(..self.offset as usize);
                 Ok(vec)
             }