Skip to content

Commit

Permalink
Address review of RcVec
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 14, 2018
1 parent 2fa1da9 commit 69b9c23
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/libsyntax/util/rc_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down

0 comments on commit 69b9c23

Please sign in to comment.