mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-02 21:17:39 +00:00
run rustfmt on libcollections folder
This commit is contained in:
parent
94ae2a2e67
commit
6414e67dba
@ -225,7 +225,7 @@ pub struct BinaryHeap<T> {
|
|||||||
/// [`peek_mut()`]: struct.BinaryHeap.html#method.peek_mut
|
/// [`peek_mut()`]: struct.BinaryHeap.html#method.peek_mut
|
||||||
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
|
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
|
||||||
pub struct PeekMut<'a, T: 'a + Ord> {
|
pub struct PeekMut<'a, T: 'a + Ord> {
|
||||||
heap: &'a mut BinaryHeap<T>
|
heap: &'a mut BinaryHeap<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
|
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
|
||||||
@ -385,9 +385,7 @@ impl<T: Ord> BinaryHeap<T> {
|
|||||||
if self.is_empty() {
|
if self.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(PeekMut {
|
Some(PeekMut { heap: self })
|
||||||
heap: self
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1126,7 +1124,9 @@ impl<T: Ord> IntoIterator for BinaryHeap<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord {
|
impl<'a, T> IntoIterator for &'a BinaryHeap<T>
|
||||||
|
where T: Ord
|
||||||
|
{
|
||||||
type Item = &'a T;
|
type Item = &'a T;
|
||||||
type IntoIter = Iter<'a, T>;
|
type IntoIter = Iter<'a, T>;
|
||||||
|
|
||||||
|
@ -63,7 +63,9 @@ pub trait ToOwned {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ToOwned for T where T: Clone {
|
impl<T> ToOwned for T
|
||||||
|
where T: Clone
|
||||||
|
{
|
||||||
type Owned = T;
|
type Owned = T;
|
||||||
fn to_owned(&self) -> T {
|
fn to_owned(&self) -> T {
|
||||||
self.clone()
|
self.clone()
|
||||||
@ -117,17 +119,19 @@ pub enum Cow<'a, B: ?Sized + 'a>
|
|||||||
{
|
{
|
||||||
/// Borrowed data.
|
/// Borrowed data.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
Borrowed(#[stable(feature = "rust1", since = "1.0.0")] &'a B),
|
Borrowed(#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
&'a B),
|
||||||
|
|
||||||
/// Owned data.
|
/// Owned data.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
Owned(
|
Owned(#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")] <B as ToOwned>::Owned
|
<B as ToOwned>::Owned),
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<'a, B: ?Sized> Clone for Cow<'a, B> where B: ToOwned {
|
impl<'a, B: ?Sized> Clone for Cow<'a, B>
|
||||||
|
where B: ToOwned
|
||||||
|
{
|
||||||
fn clone(&self) -> Cow<'a, B> {
|
fn clone(&self) -> Cow<'a, B> {
|
||||||
match *self {
|
match *self {
|
||||||
Borrowed(b) => Borrowed(b),
|
Borrowed(b) => Borrowed(b),
|
||||||
@ -139,7 +143,9 @@ impl<'a, B: ?Sized> Clone for Cow<'a, B> where B: ToOwned {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, B: ?Sized> Cow<'a, B> where B: ToOwned {
|
impl<'a, B: ?Sized> Cow<'a, B>
|
||||||
|
where B: ToOwned
|
||||||
|
{
|
||||||
/// Acquires a mutable reference to the owned form of the data.
|
/// Acquires a mutable reference to the owned form of the data.
|
||||||
///
|
///
|
||||||
/// Clones the data if it is not already owned.
|
/// Clones the data if it is not already owned.
|
||||||
@ -194,7 +200,9 @@ impl<'a, B: ?Sized> Cow<'a, B> where B: ToOwned {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<'a, B: ?Sized> Deref for Cow<'a, B> where B: ToOwned {
|
impl<'a, B: ?Sized> Deref for Cow<'a, B>
|
||||||
|
where B: ToOwned
|
||||||
|
{
|
||||||
type Target = B;
|
type Target = B;
|
||||||
|
|
||||||
fn deref(&self) -> &B {
|
fn deref(&self) -> &B {
|
||||||
@ -209,7 +217,9 @@ impl<'a, B: ?Sized> Deref for Cow<'a, B> where B: ToOwned {
|
|||||||
impl<'a, B: ?Sized> Eq for Cow<'a, B> where B: Eq + ToOwned {}
|
impl<'a, B: ?Sized> Eq for Cow<'a, B> where B: Eq + ToOwned {}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<'a, B: ?Sized> Ord for Cow<'a, B> where B: Ord + ToOwned {
|
impl<'a, B: ?Sized> Ord for Cow<'a, B>
|
||||||
|
where B: Ord + ToOwned
|
||||||
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cmp(&self, other: &Cow<'a, B>) -> Ordering {
|
fn cmp(&self, other: &Cow<'a, B>) -> Ordering {
|
||||||
Ord::cmp(&**self, &**other)
|
Ord::cmp(&**self, &**other)
|
||||||
@ -228,7 +238,9 @@ impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq<Cow<'b, C>> for Cow<'a, B>
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<'a, B: ?Sized> PartialOrd for Cow<'a, B> where B: PartialOrd + ToOwned {
|
impl<'a, B: ?Sized> PartialOrd for Cow<'a, B>
|
||||||
|
where B: PartialOrd + ToOwned
|
||||||
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partial_cmp(&self, other: &Cow<'a, B>) -> Option<Ordering> {
|
fn partial_cmp(&self, other: &Cow<'a, B>) -> Option<Ordering> {
|
||||||
PartialOrd::partial_cmp(&**self, &**other)
|
PartialOrd::partial_cmp(&**self, &**other)
|
||||||
@ -273,7 +285,9 @@ impl<'a, B: ?Sized> Default for Cow<'a, B>
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<'a, B: ?Sized> Hash for Cow<'a, B> where B: Hash + ToOwned {
|
impl<'a, B: ?Sized> Hash for Cow<'a, B>
|
||||||
|
where B: Hash + ToOwned
|
||||||
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
Hash::hash(&**self, state)
|
Hash::hash(&**self, state)
|
||||||
|
@ -276,7 +276,8 @@ impl<E: CLike> FromIterator<E> for EnumSet<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, E> IntoIterator for &'a EnumSet<E> where E: CLike
|
impl<'a, E> IntoIterator for &'a EnumSet<E>
|
||||||
|
where E: CLike
|
||||||
{
|
{
|
||||||
type Item = E;
|
type Item = E;
|
||||||
type IntoIter = Iter<E>;
|
type IntoIter = Iter<E>;
|
||||||
|
@ -225,7 +225,8 @@ impl<T> LinkedList<T> {
|
|||||||
pub fn append(&mut self, other: &mut Self) {
|
pub fn append(&mut self, other: &mut Self) {
|
||||||
match self.tail {
|
match self.tail {
|
||||||
None => mem::swap(self, other),
|
None => mem::swap(self, other),
|
||||||
Some(tail) => if let Some(other_head) = other.head.take() {
|
Some(tail) => {
|
||||||
|
if let Some(other_head) = other.head.take() {
|
||||||
unsafe {
|
unsafe {
|
||||||
(**tail).next = Some(other_head);
|
(**tail).next = Some(other_head);
|
||||||
(**other_head).prev = Some(tail);
|
(**other_head).prev = Some(tail);
|
||||||
@ -233,7 +234,8 @@ impl<T> LinkedList<T> {
|
|||||||
|
|
||||||
self.tail = other.tail.take();
|
self.tail = other.tail.take();
|
||||||
self.len += mem::replace(&mut other.len, 0);
|
self.len += mem::replace(&mut other.len, 0);
|
||||||
},
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -674,7 +676,10 @@ impl<T> LinkedList<T> {
|
|||||||
reason = "method name and placement protocol are subject to change",
|
reason = "method name and placement protocol are subject to change",
|
||||||
issue = "30172")]
|
issue = "30172")]
|
||||||
pub fn front_place(&mut self) -> FrontPlace<T> {
|
pub fn front_place(&mut self) -> FrontPlace<T> {
|
||||||
FrontPlace { list: self, node: IntermediateBox::make_place() }
|
FrontPlace {
|
||||||
|
list: self,
|
||||||
|
node: IntermediateBox::make_place(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a place for insertion at the back of the list.
|
/// Returns a place for insertion at the back of the list.
|
||||||
@ -699,7 +704,10 @@ impl<T> LinkedList<T> {
|
|||||||
reason = "method name and placement protocol are subject to change",
|
reason = "method name and placement protocol are subject to change",
|
||||||
issue = "30172")]
|
issue = "30172")]
|
||||||
pub fn back_place(&mut self) -> BackPlace<T> {
|
pub fn back_place(&mut self) -> BackPlace<T> {
|
||||||
BackPlace { list: self, node: IntermediateBox::make_place() }
|
BackPlace {
|
||||||
|
list: self,
|
||||||
|
node: IntermediateBox::make_place(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -852,7 +860,7 @@ impl<'a, T> IterMut<'a, T> {
|
|||||||
(**head).prev = node;
|
(**head).prev = node;
|
||||||
|
|
||||||
self.list.len += 1;
|
self.list.len += 1;
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1135,9 +1143,15 @@ impl<'a, T> InPlace<T> for BackPlace<'a, T> {
|
|||||||
// Ensure that `LinkedList` and its read-only iterators are covariant in their type parameters.
|
// Ensure that `LinkedList` and its read-only iterators are covariant in their type parameters.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn assert_covariance() {
|
fn assert_covariance() {
|
||||||
fn a<'a>(x: LinkedList<&'static str>) -> LinkedList<&'a str> { x }
|
fn a<'a>(x: LinkedList<&'static str>) -> LinkedList<&'a str> {
|
||||||
fn b<'i, 'a>(x: Iter<'i, &'static str>) -> Iter<'i, &'a str> { x }
|
x
|
||||||
fn c<'a>(x: IntoIter<&'static str>) -> IntoIter<&'a str> { x }
|
}
|
||||||
|
fn b<'i, 'a>(x: Iter<'i, &'static str>) -> Iter<'i, &'a str> {
|
||||||
|
x
|
||||||
|
}
|
||||||
|
fn c<'a>(x: IntoIter<&'static str>) -> IntoIter<&'a str> {
|
||||||
|
x
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
@ -1697,11 +1697,7 @@ impl str {
|
|||||||
debug_assert!('Σ'.len_utf8() == 2);
|
debug_assert!('Σ'.len_utf8() == 2);
|
||||||
let is_word_final = case_ignoreable_then_cased(from[..i].chars().rev()) &&
|
let is_word_final = case_ignoreable_then_cased(from[..i].chars().rev()) &&
|
||||||
!case_ignoreable_then_cased(from[i + 2..].chars());
|
!case_ignoreable_then_cased(from[i + 2..].chars());
|
||||||
to.push_str(if is_word_final {
|
to.push_str(if is_word_final { "ς" } else { "σ" });
|
||||||
"ς"
|
|
||||||
} else {
|
|
||||||
"σ"
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn case_ignoreable_then_cased<I: Iterator<Item = char>>(iter: I) -> bool {
|
fn case_ignoreable_then_cased<I: Iterator<Item = char>>(iter: I) -> bool {
|
||||||
|
@ -542,11 +542,7 @@ impl String {
|
|||||||
unsafe { *xs.get_unchecked(i) }
|
unsafe { *xs.get_unchecked(i) }
|
||||||
}
|
}
|
||||||
fn safe_get(xs: &[u8], i: usize, total: usize) -> u8 {
|
fn safe_get(xs: &[u8], i: usize, total: usize) -> u8 {
|
||||||
if i >= total {
|
if i >= total { 0 } else { unsafe_get(xs, i) }
|
||||||
0
|
|
||||||
} else {
|
|
||||||
unsafe_get(xs, i)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut res = String::with_capacity(total);
|
let mut res = String::with_capacity(total);
|
||||||
@ -976,7 +972,7 @@ impl String {
|
|||||||
pub fn push(&mut self, ch: char) {
|
pub fn push(&mut self, ch: char) {
|
||||||
match ch.len_utf8() {
|
match ch.len_utf8() {
|
||||||
1 => self.vec.push(ch as u8),
|
1 => self.vec.push(ch as u8),
|
||||||
_ => self.vec.extend_from_slice(ch.encode_utf8(&mut [0;4]).as_bytes()),
|
_ => self.vec.extend_from_slice(ch.encode_utf8(&mut [0; 4]).as_bytes()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1935,7 +1931,7 @@ impl<'a> FromIterator<String> for Cow<'a, str> {
|
|||||||
|
|
||||||
#[stable(feature = "from_string_for_vec_u8", since = "1.14.0")]
|
#[stable(feature = "from_string_for_vec_u8", since = "1.14.0")]
|
||||||
impl From<String> for Vec<u8> {
|
impl From<String> for Vec<u8> {
|
||||||
fn from(string : String) -> Vec<u8> {
|
fn from(string: String) -> Vec<u8> {
|
||||||
string.into_bytes()
|
string.into_bytes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,11 +206,7 @@ impl<T> VecDeque<T> {
|
|||||||
unsafe fn wrap_copy(&self, dst: usize, src: usize, len: usize) {
|
unsafe fn wrap_copy(&self, dst: usize, src: usize, len: usize) {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn diff(a: usize, b: usize) -> usize {
|
fn diff(a: usize, b: usize) -> usize {
|
||||||
if a <= b {
|
if a <= b { b - a } else { a - b }
|
||||||
b - a
|
|
||||||
} else {
|
|
||||||
a - b
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
debug_assert!(cmp::min(diff(dst, src), self.cap() - diff(dst, src)) + len <= self.cap(),
|
debug_assert!(cmp::min(diff(dst, src), self.cap() - diff(dst, src)) + len <= self.cap(),
|
||||||
"wrc dst={} src={} len={} cap={}",
|
"wrc dst={} src={} len={} cap={}",
|
||||||
@ -1293,9 +1289,7 @@ impl<T> VecDeque<T> {
|
|||||||
|
|
||||||
let contiguous = self.is_contiguous();
|
let contiguous = self.is_contiguous();
|
||||||
|
|
||||||
match (contiguous,
|
match (contiguous, distance_to_tail <= distance_to_head, idx >= self.tail) {
|
||||||
distance_to_tail <= distance_to_head,
|
|
||||||
idx >= self.tail) {
|
|
||||||
(true, true, _) if index == 0 => {
|
(true, true, _) if index == 0 => {
|
||||||
// push_front
|
// push_front
|
||||||
//
|
//
|
||||||
@ -1513,9 +1507,7 @@ impl<T> VecDeque<T> {
|
|||||||
|
|
||||||
let contiguous = self.is_contiguous();
|
let contiguous = self.is_contiguous();
|
||||||
|
|
||||||
match (contiguous,
|
match (contiguous, distance_to_tail <= distance_to_head, idx >= self.tail) {
|
||||||
distance_to_tail <= distance_to_head,
|
|
||||||
idx >= self.tail) {
|
|
||||||
(true, true, _) => {
|
(true, true, _) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
// contiguous, remove closer to tail:
|
// contiguous, remove closer to tail:
|
||||||
@ -1812,7 +1804,7 @@ fn wrap_index(index: usize, size: usize) -> usize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the two slices that cover the VecDeque's valid range
|
/// Returns the two slices that cover the VecDeque's valid range
|
||||||
trait RingSlices : Sized {
|
trait RingSlices: Sized {
|
||||||
fn slice(self, from: usize, to: usize) -> Self;
|
fn slice(self, from: usize, to: usize) -> Self;
|
||||||
fn split_at(self, i: usize) -> (Self, Self);
|
fn split_at(self, i: usize) -> (Self, Self);
|
||||||
|
|
||||||
@ -1895,7 +1887,7 @@ impl<'a, T> Iterator for Iter<'a, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fold<Acc, F>(self, mut accum: Acc, mut f: F) -> Acc
|
fn fold<Acc, F>(self, mut accum: Acc, mut f: F) -> Acc
|
||||||
where F: FnMut(Acc, Self::Item) -> Acc,
|
where F: FnMut(Acc, Self::Item) -> Acc
|
||||||
{
|
{
|
||||||
let (front, back) = RingSlices::ring_slices(self.ring, self.head, self.tail);
|
let (front, back) = RingSlices::ring_slices(self.ring, self.head, self.tail);
|
||||||
accum = front.iter().fold(accum, &mut f);
|
accum = front.iter().fold(accum, &mut f);
|
||||||
@ -1959,7 +1951,7 @@ impl<'a, T> Iterator for IterMut<'a, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fold<Acc, F>(self, mut accum: Acc, mut f: F) -> Acc
|
fn fold<Acc, F>(self, mut accum: Acc, mut f: F) -> Acc
|
||||||
where F: FnMut(Acc, Self::Item) -> Acc,
|
where F: FnMut(Acc, Self::Item) -> Acc
|
||||||
{
|
{
|
||||||
let (front, back) = RingSlices::ring_slices(self.ring, self.head, self.tail);
|
let (front, back) = RingSlices::ring_slices(self.ring, self.head, self.tail);
|
||||||
accum = front.iter_mut().fold(accum, &mut f);
|
accum = front.iter_mut().fold(accum, &mut f);
|
||||||
@ -2082,8 +2074,7 @@ impl<'a, T: 'a> Drop for Drain<'a, T> {
|
|||||||
(_, 0) => {
|
(_, 0) => {
|
||||||
source_deque.head = drain_tail;
|
source_deque.head = drain_tail;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => unsafe {
|
||||||
unsafe {
|
|
||||||
if tail_len <= head_len {
|
if tail_len <= head_len {
|
||||||
source_deque.tail = source_deque.wrap_sub(drain_head, tail_len);
|
source_deque.tail = source_deque.wrap_sub(drain_head, tail_len);
|
||||||
source_deque.wrap_copy(source_deque.tail, orig_tail, tail_len);
|
source_deque.wrap_copy(source_deque.tail, orig_tail, tail_len);
|
||||||
@ -2091,8 +2082,7 @@ impl<'a, T: 'a> Drop for Drain<'a, T> {
|
|||||||
source_deque.head = source_deque.wrap_add(drain_tail, head_len);
|
source_deque.head = source_deque.wrap_add(drain_tail, head_len);
|
||||||
source_deque.wrap_copy(drain_tail, drain_head, head_len);
|
source_deque.wrap_copy(drain_tail, drain_head, head_len);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2288,10 +2278,8 @@ impl<T> From<Vec<T>> for VecDeque<T> {
|
|||||||
|
|
||||||
// We need to extend the buf if it's not a power of two, too small
|
// We need to extend the buf if it's not a power of two, too small
|
||||||
// or doesn't have at least one free space
|
// or doesn't have at least one free space
|
||||||
if !buf.cap().is_power_of_two()
|
if !buf.cap().is_power_of_two() || (buf.cap() < (MINIMUM_CAPACITY + 1)) ||
|
||||||
|| (buf.cap() < (MINIMUM_CAPACITY + 1))
|
(buf.cap() == len) {
|
||||||
|| (buf.cap() == len)
|
|
||||||
{
|
|
||||||
let cap = cmp::max(buf.cap() + 1, MINIMUM_CAPACITY + 1).next_power_of_two();
|
let cap = cmp::max(buf.cap() + 1, MINIMUM_CAPACITY + 1).next_power_of_two();
|
||||||
buf.reserve_exact(len, cap - len);
|
buf.reserve_exact(len, cap - len);
|
||||||
}
|
}
|
||||||
@ -2299,7 +2287,7 @@ impl<T> From<Vec<T>> for VecDeque<T> {
|
|||||||
VecDeque {
|
VecDeque {
|
||||||
tail: 0,
|
tail: 0,
|
||||||
head: len,
|
head: len,
|
||||||
buf: buf
|
buf: buf,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2324,18 +2312,17 @@ impl<T> From<VecDeque<T>> for Vec<T> {
|
|||||||
// do this in at most three copy moves.
|
// do this in at most three copy moves.
|
||||||
if (cap - tail) > head {
|
if (cap - tail) > head {
|
||||||
// right hand block is the long one; move that enough for the left
|
// right hand block is the long one; move that enough for the left
|
||||||
ptr::copy(
|
ptr::copy(buf.offset(tail as isize),
|
||||||
buf.offset(tail as isize),
|
|
||||||
buf.offset((tail - head) as isize),
|
buf.offset((tail - head) as isize),
|
||||||
cap - tail);
|
cap - tail);
|
||||||
// copy left in the end
|
// copy left in the end
|
||||||
ptr::copy(buf, buf.offset((cap - head) as isize), head);
|
ptr::copy(buf, buf.offset((cap - head) as isize), head);
|
||||||
// shift the new thing to the start
|
// shift the new thing to the start
|
||||||
ptr::copy(buf.offset((tail-head) as isize), buf, len);
|
ptr::copy(buf.offset((tail - head) as isize), buf, len);
|
||||||
} else {
|
} else {
|
||||||
// left hand block is the long one, we can do it in two!
|
// left hand block is the long one, we can do it in two!
|
||||||
ptr::copy(buf, buf.offset((cap-tail) as isize), head);
|
ptr::copy(buf, buf.offset((cap - tail) as isize), head);
|
||||||
ptr::copy(buf.offset(tail as isize), buf, cap-tail);
|
ptr::copy(buf.offset(tail as isize), buf, cap - tail);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Need to use N swaps to move the ring
|
// Need to use N swaps to move the ring
|
||||||
@ -2693,19 +2680,19 @@ mod tests {
|
|||||||
let cap = (2i32.pow(cap_pwr) - 1) as usize;
|
let cap = (2i32.pow(cap_pwr) - 1) as usize;
|
||||||
|
|
||||||
// In these cases there is enough free space to solve it with copies
|
// In these cases there is enough free space to solve it with copies
|
||||||
for len in 0..((cap+1)/2) {
|
for len in 0..((cap + 1) / 2) {
|
||||||
// Test contiguous cases
|
// Test contiguous cases
|
||||||
for offset in 0..(cap-len) {
|
for offset in 0..(cap - len) {
|
||||||
create_vec_and_test_convert(cap, offset, len)
|
create_vec_and_test_convert(cap, offset, len)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test cases where block at end of buffer is bigger than block at start
|
// Test cases where block at end of buffer is bigger than block at start
|
||||||
for offset in (cap-len)..(cap-(len/2)) {
|
for offset in (cap - len)..(cap - (len / 2)) {
|
||||||
create_vec_and_test_convert(cap, offset, len)
|
create_vec_and_test_convert(cap, offset, len)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test cases where block at start of buffer is bigger than block at end
|
// Test cases where block at start of buffer is bigger than block at end
|
||||||
for offset in (cap-(len/2))..cap {
|
for offset in (cap - (len / 2))..cap {
|
||||||
create_vec_and_test_convert(cap, offset, len)
|
create_vec_and_test_convert(cap, offset, len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2714,19 +2701,19 @@ mod tests {
|
|||||||
// the ring will use swapping when:
|
// the ring will use swapping when:
|
||||||
// (cap + 1 - offset) > (cap + 1 - len) && (len - (cap + 1 - offset)) > (cap + 1 - len))
|
// (cap + 1 - offset) > (cap + 1 - len) && (len - (cap + 1 - offset)) > (cap + 1 - len))
|
||||||
// right block size > free space && left block size > free space
|
// right block size > free space && left block size > free space
|
||||||
for len in ((cap+1)/2)..cap {
|
for len in ((cap + 1) / 2)..cap {
|
||||||
// Test contiguous cases
|
// Test contiguous cases
|
||||||
for offset in 0..(cap-len) {
|
for offset in 0..(cap - len) {
|
||||||
create_vec_and_test_convert(cap, offset, len)
|
create_vec_and_test_convert(cap, offset, len)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test cases where block at end of buffer is bigger than block at start
|
// Test cases where block at end of buffer is bigger than block at start
|
||||||
for offset in (cap-len)..(cap-(len/2)) {
|
for offset in (cap - len)..(cap - (len / 2)) {
|
||||||
create_vec_and_test_convert(cap, offset, len)
|
create_vec_and_test_convert(cap, offset, len)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test cases where block at start of buffer is bigger than block at end
|
// Test cases where block at start of buffer is bigger than block at end
|
||||||
for offset in (cap-(len/2))..cap {
|
for offset in (cap - (len / 2))..cap {
|
||||||
create_vec_and_test_convert(cap, offset, len)
|
create_vec_and_test_convert(cap, offset, len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user