Skip to content

Commit 90b9469

Browse files
committed
Revert "Optimize VecDeque::append"
This reverts commit 11e488b.
1 parent 9a41cfa commit 90b9469

File tree

1 file changed

+2
-27
lines changed

1 file changed

+2
-27
lines changed

src/liballoc/collections/vec_deque.rs

+2-27
Original file line numberDiff line numberDiff line change
@@ -202,22 +202,6 @@ impl<T> VecDeque<T> {
202202
len);
203203
}
204204

205-
/// Copies all values from `src` to `self`, wrapping around if needed.
206-
/// Assumes capacity is sufficient.
207-
#[inline]
208-
unsafe fn copy_slice(&mut self, src: &[T]) {
209-
let dst_high_ptr = self.ptr().add(self.head);
210-
let dst_high_len = self.cap() - self.head;
211-
212-
let split = cmp::min(src.len(), dst_high_len);
213-
let (src_high, src_low) = src.split_at(split);
214-
215-
ptr::copy_nonoverlapping(src_high.as_ptr(), dst_high_ptr, src_high.len());
216-
ptr::copy_nonoverlapping(src_low.as_ptr(), self.ptr(), src_low.len());
217-
218-
self.head = self.wrap_add(self.head, src.len());
219-
}
220-
221205
/// Copies a potentially wrapping block of memory len long from src to dest.
222206
/// (abs(dst - src) + len) must be no larger than cap() (There must be at
223207
/// most one continuous overlapping region between src and dest).
@@ -1850,17 +1834,8 @@ impl<T> VecDeque<T> {
18501834
#[inline]
18511835
#[stable(feature = "append", since = "1.4.0")]
18521836
pub fn append(&mut self, other: &mut Self) {
1853-
// Guarantees there is space in `self` for `other
1854-
self.reserve(other.len());
1855-
1856-
unsafe {
1857-
let (src_high, src_low) = other.as_slices();
1858-
self.copy_slice(src_low);
1859-
self.copy_slice(src_high);
1860-
}
1861-
1862-
// Some values now exist in both `other` and `self` but are made inaccessible in `other`.
1863-
other.tail = other.head;
1837+
// naive impl
1838+
self.extend(other.drain(..));
18641839
}
18651840

18661841
/// Retains only the elements specified by the predicate.

0 commit comments

Comments
 (0)