Skip to content

Commit 402c699

Browse files
authored
Rollup merge of #54851 - alexcrichton:revert-optimize, r=sfackler
Fix a regression in 1.30 by reverting #53564 Investigation on #54477 revealed #53564 as the culprit in the regression for that crate. I've reproduced the regression with the [detailed test cases provided](#54477 (comment)). While we figure out how to fix the regression this commit reverts the current culprit.
2 parents 42fcde8 + 70ae43f commit 402c699

File tree

1 file changed

+5
-47
lines changed

1 file changed

+5
-47
lines changed

src/liballoc/collections/vec_deque.rs

+5-47
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
use core::cmp::Ordering;
2121
use core::fmt;
22-
use core::isize;
2322
use core::iter::{repeat, FromIterator, FusedIterator};
2423
use core::mem;
2524
use core::ops::Bound::{Excluded, Included, Unbounded};
@@ -203,33 +202,6 @@ impl<T> VecDeque<T> {
203202
len);
204203
}
205204

206-
/// Copies all values from `src` to the back of `self`, wrapping around if needed.
207-
///
208-
/// # Safety
209-
///
210-
/// The capacity must be sufficient to hold self.len() + src.len() elements.
211-
/// If so, this function never panics.
212-
#[inline]
213-
unsafe fn copy_slice(&mut self, src: &[T]) {
214-
/// This is guaranteed by `RawVec`.
215-
debug_assert!(self.capacity() <= isize::MAX as usize);
216-
217-
let expected_new_len = self.len() + src.len();
218-
debug_assert!(self.capacity() >= expected_new_len);
219-
220-
let dst_high_ptr = self.ptr().add(self.head);
221-
let dst_high_len = self.cap() - self.head;
222-
223-
let split = cmp::min(src.len(), dst_high_len);
224-
let (src_high, src_low) = src.split_at(split);
225-
226-
ptr::copy_nonoverlapping(src_high.as_ptr(), dst_high_ptr, src_high.len());
227-
ptr::copy_nonoverlapping(src_low.as_ptr(), self.ptr(), src_low.len());
228-
229-
self.head = self.wrap_add(self.head, src.len());
230-
debug_assert!(self.len() == expected_new_len);
231-
}
232-
233205
/// Copies a potentially wrapping block of memory len long from src to dest.
234206
/// (abs(dst - src) + len) must be no larger than cap() (There must be at
235207
/// most one continuous overlapping region between src and dest).
@@ -1052,7 +1024,7 @@ impl<T> VecDeque<T> {
10521024
iter: Iter {
10531025
tail: drain_tail,
10541026
head: drain_head,
1055-
ring: unsafe { self.buffer_as_slice() },
1027+
ring: unsafe { self.buffer_as_mut_slice() },
10561028
},
10571029
}
10581030
}
@@ -1862,22 +1834,8 @@ impl<T> VecDeque<T> {
18621834
#[inline]
18631835
#[stable(feature = "append", since = "1.4.0")]
18641836
pub fn append(&mut self, other: &mut Self) {
1865-
unsafe {
1866-
// Guarantees there is space in `self` for `other`.
1867-
self.reserve(other.len());
1868-
1869-
{
1870-
let (src_high, src_low) = other.as_slices();
1871-
1872-
// This is only safe because copy_slice never panics when capacity is sufficient.
1873-
self.copy_slice(src_low);
1874-
self.copy_slice(src_high);
1875-
}
1876-
1877-
// Some values now exist in both `other` and `self` but are made inaccessible
1878-
// in`other`.
1879-
other.tail = other.head;
1880-
}
1837+
// naive impl
1838+
self.extend(other.drain(..));
18811839
}
18821840

18831841
/// Retains only the elements specified by the predicate.
@@ -2635,8 +2593,8 @@ impl<T> From<VecDeque<T>> for Vec<T> {
26352593
let mut right_offset = 0;
26362594
for i in left_edge..right_edge {
26372595
right_offset = (i - left_edge) % (cap - right_edge);
2638-
let src = right_edge + right_offset;
2639-
ptr::swap(buf.add(i), buf.add(src));
2596+
let src: isize = (right_edge + right_offset) as isize;
2597+
ptr::swap(buf.add(i), buf.offset(src));
26402598
}
26412599
let n_ops = right_edge - left_edge;
26422600
left_edge += n_ops;

0 commit comments

Comments
 (0)