about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-10-06 00:44:11 +0000
committerbors <bors@rust-lang.org>2018-10-06 00:44:11 +0000
commitac841e74502183cde08e462d98cc55752abd000a (patch)
tree5459e65f4c6e10cc9b02b1c31150fdc337f9446c /src/liballoc
parentfddcd316af98583ebebfc40f6a25bec3f4e5fccc (diff)
parent51334c96b3810c2a4c299715fd7fe25da84146fc (diff)
downloadrust-ac841e74502183cde08e462d98cc55752abd000a.tar.gz
rust-ac841e74502183cde08e462d98cc55752abd000a.zip
Auto merge of #54859 - pietroalbini:rollup, r=pietroalbini
Rollup of 11 pull requests

Successful merges:

 - #54078 (Expand the documentation for the `std::sync` module)
 - #54717 (Cleanup rustc/ty part 1)
 - #54781 (Add examples to `TyKind::FnDef` and `TyKind::FnPtr` docs)
 - #54787 (Only warn about unused `mut` in user-written code)
 - #54804 (add suggestion for inverted function parameters)
 - #54812 (Regression test for #32382.)
 - #54833 (make `Parser::parse_foreign_item()` return a foreign item or error)
 - #54834 (rustdoc: overflow:auto doesn't work nicely on small screens)
 - #54838 (Fix typo in src/libsyntax/parse/parser.rs)
 - #54851 (Fix a regression in 1.30 by reverting #53564)
 - #54853 (Remove unneccessary error from test, revealing NLL error.)

Failed merges:

r? @ghost
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/collections/vec_deque.rs52
1 files changed, 5 insertions, 47 deletions
diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs
index c53549ab85d..571f35a2031 100644
--- a/src/liballoc/collections/vec_deque.rs
+++ b/src/liballoc/collections/vec_deque.rs
@@ -19,7 +19,6 @@
 
 use core::cmp::Ordering;
 use core::fmt;
-use core::isize;
 use core::iter::{repeat, FromIterator, FusedIterator};
 use core::mem;
 use core::ops::Bound::{Excluded, Included, Unbounded};
@@ -203,33 +202,6 @@ impl<T> VecDeque<T> {
                                  len);
     }
 
-    /// Copies all values from `src` to the back of `self`, wrapping around if needed.
-    ///
-    /// # Safety
-    ///
-    /// The capacity must be sufficient to hold self.len() + src.len() elements.
-    /// If so, this function never panics.
-    #[inline]
-    unsafe fn copy_slice(&mut self, src: &[T]) {
-        /// This is guaranteed by `RawVec`.
-        debug_assert!(self.capacity() <= isize::MAX as usize);
-
-        let expected_new_len = self.len() + src.len();
-        debug_assert!(self.capacity() >= expected_new_len);
-
-        let dst_high_ptr = self.ptr().add(self.head);
-        let dst_high_len = self.cap() - self.head;
-
-        let split = cmp::min(src.len(), dst_high_len);
-        let (src_high, src_low) = src.split_at(split);
-
-        ptr::copy_nonoverlapping(src_high.as_ptr(), dst_high_ptr, src_high.len());
-        ptr::copy_nonoverlapping(src_low.as_ptr(), self.ptr(), src_low.len());
-
-        self.head = self.wrap_add(self.head, src.len());
-        debug_assert!(self.len() == expected_new_len);
-    }
-
     /// Copies a potentially wrapping block of memory len long from src to dest.
     /// (abs(dst - src) + len) must be no larger than cap() (There must be at
     /// most one continuous overlapping region between src and dest).
@@ -1052,7 +1024,7 @@ impl<T> VecDeque<T> {
             iter: Iter {
                 tail: drain_tail,
                 head: drain_head,
-                ring: unsafe { self.buffer_as_slice() },
+                ring: unsafe { self.buffer_as_mut_slice() },
             },
         }
     }
@@ -1862,22 +1834,8 @@ impl<T> VecDeque<T> {
     #[inline]
     #[stable(feature = "append", since = "1.4.0")]
     pub fn append(&mut self, other: &mut Self) {
-        unsafe {
-            // Guarantees there is space in `self` for `other`.
-            self.reserve(other.len());
-
-            {
-                let (src_high, src_low) = other.as_slices();
-
-                // This is only safe because copy_slice never panics when capacity is sufficient.
-                self.copy_slice(src_low);
-                self.copy_slice(src_high);
-            }
-
-            // Some values now exist in both `other` and `self` but are made inaccessible
-            // in`other`.
-            other.tail = other.head;
-        }
+        // naive impl
+        self.extend(other.drain(..));
     }
 
     /// Retains only the elements specified by the predicate.
@@ -2635,8 +2593,8 @@ impl<T> From<VecDeque<T>> for Vec<T> {
                         let mut right_offset = 0;
                         for i in left_edge..right_edge {
                             right_offset = (i - left_edge) % (cap - right_edge);
-                            let src = right_edge + right_offset;
-                            ptr::swap(buf.add(i), buf.add(src));
+                            let src: isize = (right_edge + right_offset) as isize;
+                            ptr::swap(buf.add(i), buf.offset(src));
                         }
                         let n_ops = right_edge - left_edge;
                         left_edge += n_ops;