Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #40626

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
50cede0
documented order of conversion between u32 an ipv4addr
Mar 17, 2017
c96491f
Update libc to 0.2.21
malbarbo Mar 7, 2017
5798817
Fix c_char (u8 -> i8) definition for i686-linux-android
malbarbo Mar 16, 2017
3435c60
Fix libc::bind call on aarch64-linux-android
malbarbo Mar 17, 2017
963d4df
minor wording tweak to slice::{as_ptr, as_mut_ptr}
QuietMisdreavus Mar 17, 2017
ec8ecf4
Fix typo in mutex.rs docs
ScottAbbey Mar 17, 2017
33a5665
Stabilize move_cell feature, closes #39264
aturon Mar 15, 2017
65b7c4e
Stabilize expect_err feature, closes #39041
aturon Mar 15, 2017
d38ea8b
Stabilize ptr_unaligned feature, closes #37955
aturon Mar 15, 2017
9511fe6
Stabilize process_abort feature, closes #37838
aturon Mar 15, 2017
10510ae
Stabilize ptr_eq feature, closes #36497
aturon Mar 15, 2017
37b38a2
Stabilize btree_range, closes #27787
aturon Mar 15, 2017
48890d4
Stabilize ordering_chaining, closes #37053
aturon Mar 15, 2017
a8f4a1b
Stabilize rc_raw feature, closes #37197
aturon Mar 15, 2017
1241a88
Minor fixups to fix tidy errors
alexcrichton Mar 15, 2017
a0fb726
Add docs for sort_unstable to unstable book
Mar 17, 2017
2976ddb
Fix a spelling error in HashMap documentation, and slightly reword it…
jswalden Mar 18, 2017
9fb737b
Update the cargo submodule again
alexcrichton Mar 18, 2017
d3c72c2
Rollup merge of #40317 - malbarbo:update-libc, r=alexcrichton
frewsxcv Mar 18, 2017
7387fd5
Rollup merge of #40538 - aturon:stab-1.17, r=alexcrichton
frewsxcv Mar 18, 2017
a3aaa0e
Rollup merge of #40590 - z1mvader:master, r=steveklabnik
frewsxcv Mar 18, 2017
ff630b3
Rollup merge of #40603 - QuietMisdreavus:slice-ptr-docs, r=GuillaumeG…
frewsxcv Mar 18, 2017
08a4a12
Rollup merge of #40611 - ScottAbbey:patch-1, r=GuillaumeGomez
frewsxcv Mar 18, 2017
45d9514
Rollup merge of #40619 - stjepang:unstable-book-sort-unstable, r=stev…
frewsxcv Mar 18, 2017
7a8be40
Rollup merge of #40621 - jswalden:dependant-spelling-fix, r=sfackler
frewsxcv Mar 18, 2017
e7e229e
Rollup merge of #40625 - alexcrichton:update-cargo-again, r=alexcrichton
frewsxcv Mar 18, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/doc/unstable-book/src/sort-unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,35 @@ The tracking issue for this feature is: [#40585]

------------------------

The default `sort` method on slices is stable. In other words, it guarantees
that the original order of equal elements is preserved after sorting. The
method has several undesirable characteristics:

1. It allocates a sizable chunk of memory.
2. If you don't need stability, it is not as performant as it could be.

An alternative is the new `sort_unstable` feature, which includes these
methods for sorting slices:

1. `sort_unstable`
2. `sort_unstable_by`
3. `sort_unstable_by_key`

Unstable sorting is generally faster and makes no allocations. The majority
of real-world sorting needs doesn't require stability, so these methods can
very often come in handy.

Another important difference is that `sort` lives in `libstd` and
`sort_unstable` lives in `libcore`. The reason is that the former makes
allocations and the latter doesn't.

A simple example:

```rust
#![feature(sort_unstable)]

let mut v = [-5, 4, 1, -3, 2];

v.sort_unstable();
assert!(v == [-5, -3, 1, 2, 4]);
```
31 changes: 13 additions & 18 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,15 @@ impl<T> Arc<T> {
/// # Examples
///
/// ```
/// #![feature(rc_raw)]
///
/// use std::sync::Arc;
///
/// let x = Arc::new(10);
/// let x_ptr = Arc::into_raw(x);
/// assert_eq!(unsafe { *x_ptr }, 10);
/// ```
#[unstable(feature = "rc_raw", issue = "37197")]
pub fn into_raw(this: Self) -> *mut T {
let ptr = unsafe { &mut (**this.ptr).data as *mut _ };
#[stable(feature = "rc_raw", since = "1.17.0")]
pub fn into_raw(this: Self) -> *const T {
let ptr = unsafe { &(**this.ptr).data as *const _ };
mem::forget(this);
ptr
}
Expand All @@ -315,8 +313,6 @@ impl<T> Arc<T> {
/// # Examples
///
/// ```
/// #![feature(rc_raw)]
///
/// use std::sync::Arc;
///
/// let x = Arc::new(10);
Expand All @@ -332,11 +328,14 @@ impl<T> Arc<T> {
///
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!
/// ```
#[unstable(feature = "rc_raw", issue = "37197")]
pub unsafe fn from_raw(ptr: *mut T) -> Self {
#[stable(feature = "rc_raw", since = "1.17.0")]
pub unsafe fn from_raw(ptr: *const T) -> Self {
// To find the corresponding pointer to the `ArcInner` we need to subtract the offset of the
// `data` field from the pointer.
Arc { ptr: Shared::new((ptr as *mut u8).offset(-offset_of!(ArcInner<T>, data)) as *mut _) }
let ptr = (ptr as *const u8).offset(-offset_of!(ArcInner<T>, data));
Arc {
ptr: Shared::new(ptr as *const _),
}
}
}

Expand Down Expand Up @@ -448,7 +447,7 @@ impl<T: ?Sized> Arc<T> {
// Non-inlined part of `drop`.
#[inline(never)]
unsafe fn drop_slow(&mut self) {
let ptr = *self.ptr;
let ptr = self.ptr.as_mut_ptr();

// Destroy the data at this time, even though we may not free the box
// allocation itself (there may still be weak pointers lying around).
Expand All @@ -461,17 +460,13 @@ impl<T: ?Sized> Arc<T> {
}

#[inline]
#[unstable(feature = "ptr_eq",
reason = "newly added",
issue = "36497")]
#[stable(feature = "ptr_eq", since = "1.17.0")]
/// Returns true if the two `Arc`s point to the same value (not
/// just values that compare as equal).
///
/// # Examples
///
/// ```
/// #![feature(ptr_eq)]
///
/// use std::sync::Arc;
///
/// let five = Arc::new(5);
Expand Down Expand Up @@ -628,7 +623,7 @@ impl<T: Clone> Arc<T> {
// As with `get_mut()`, the unsafety is ok because our reference was
// either unique to begin with, or became one upon cloning the contents.
unsafe {
let inner = &mut **this.ptr;
let inner = &mut *this.ptr.as_mut_ptr();
&mut inner.data
}
}
Expand Down Expand Up @@ -671,7 +666,7 @@ impl<T: ?Sized> Arc<T> {
// the Arc itself to be `mut`, so we're returning the only possible
// reference to the inner data.
unsafe {
let inner = &mut **this.ptr;
let inner = &mut *this.ptr.as_mut_ptr();
Some(&mut inner.data)
}
} else {
Expand Down
28 changes: 10 additions & 18 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,17 +364,15 @@ impl<T> Rc<T> {
/// # Examples
///
/// ```
/// #![feature(rc_raw)]
///
/// use std::rc::Rc;
///
/// let x = Rc::new(10);
/// let x_ptr = Rc::into_raw(x);
/// assert_eq!(unsafe { *x_ptr }, 10);
/// ```
#[unstable(feature = "rc_raw", issue = "37197")]
pub fn into_raw(this: Self) -> *mut T {
let ptr = unsafe { &mut (**this.ptr).value as *mut _ };
#[stable(feature = "rc_raw", since = "1.17.0")]
pub fn into_raw(this: Self) -> *const T {
let ptr = unsafe { &mut (*this.ptr.as_mut_ptr()).value as *const _ };
mem::forget(this);
ptr
}
Expand All @@ -392,8 +390,6 @@ impl<T> Rc<T> {
/// # Examples
///
/// ```
/// #![feature(rc_raw)]
///
/// use std::rc::Rc;
///
/// let x = Rc::new(10);
Expand All @@ -409,11 +405,11 @@ impl<T> Rc<T> {
///
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!
/// ```
#[unstable(feature = "rc_raw", issue = "37197")]
pub unsafe fn from_raw(ptr: *mut T) -> Self {
#[stable(feature = "rc_raw", since = "1.17.0")]
pub unsafe fn from_raw(ptr: *const T) -> Self {
// To find the corresponding pointer to the `RcBox` we need to subtract the offset of the
// `value` field from the pointer.
Rc { ptr: Shared::new((ptr as *mut u8).offset(-offset_of!(RcBox<T>, value)) as *mut _) }
Rc { ptr: Shared::new((ptr as *const u8).offset(-offset_of!(RcBox<T>, value)) as *const _) }
}
}

Expand Down Expand Up @@ -543,25 +539,21 @@ impl<T: ?Sized> Rc<T> {
#[stable(feature = "rc_unique", since = "1.4.0")]
pub fn get_mut(this: &mut Self) -> Option<&mut T> {
if Rc::is_unique(this) {
let inner = unsafe { &mut **this.ptr };
let inner = unsafe { &mut *this.ptr.as_mut_ptr() };
Some(&mut inner.value)
} else {
None
}
}

#[inline]
#[unstable(feature = "ptr_eq",
reason = "newly added",
issue = "36497")]
#[stable(feature = "ptr_eq", since = "1.17.0")]
/// Returns true if the two `Rc`s point to the same value (not
/// just values that compare as equal).
///
/// # Examples
///
/// ```
/// #![feature(ptr_eq)]
///
/// use std::rc::Rc;
///
/// let five = Rc::new(5);
Expand Down Expand Up @@ -631,7 +623,7 @@ impl<T: Clone> Rc<T> {
// reference count is guaranteed to be 1 at this point, and we required
// the `Rc<T>` itself to be `mut`, so we're returning the only possible
// reference to the inner value.
let inner = unsafe { &mut **this.ptr };
let inner = unsafe { &mut *this.ptr.as_mut_ptr() };
&mut inner.value
}
}
Expand Down Expand Up @@ -677,7 +669,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Rc<T> {
/// ```
fn drop(&mut self) {
unsafe {
let ptr = *self.ptr;
let ptr = self.ptr.as_mut_ptr();

self.dec_strong();
if self.strong() == 0 {
Expand Down
14 changes: 4 additions & 10 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ pub struct ValuesMut<'a, K: 'a, V: 'a> {
}

/// An iterator over a sub-range of BTreeMap's entries.
#[stable(feature = "btree_range", since = "1.17.0")]
pub struct Range<'a, K: 'a, V: 'a> {
front: Handle<NodeRef<marker::Immut<'a>, K, V, marker::Leaf>, marker::Edge>,
back: Handle<NodeRef<marker::Immut<'a>, K, V, marker::Leaf>, marker::Edge>,
Expand All @@ -351,6 +352,7 @@ impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Range<'a, K, V>
}

/// A mutable iterator over a sub-range of BTreeMap's entries.
#[stable(feature = "btree_range", since = "1.17.0")]
pub struct RangeMut<'a, K: 'a, V: 'a> {
front: Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>,
back: Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>,
Expand Down Expand Up @@ -724,8 +726,6 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// Basic usage:
///
/// ```
/// #![feature(btree_range, collections_bound)]
///
/// use std::collections::BTreeMap;
/// use std::collections::Bound::Included;
///
Expand All @@ -738,9 +738,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// }
/// assert_eq!(Some((&5, &"b")), map.range(4..).next());
/// ```
#[unstable(feature = "btree_range",
reason = "matches collection reform specification, waiting for dust to settle",
issue = "27787")]
#[stable(feature = "btree_range", since = "1.17.0")]
pub fn range<T: ?Sized, R>(&self, range: R) -> Range<K, V>
where T: Ord, K: Borrow<T>, R: RangeArgument<T>
{
Expand Down Expand Up @@ -768,8 +766,6 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// Basic usage:
///
/// ```
/// #![feature(btree_range)]
///
/// use std::collections::BTreeMap;
///
/// let mut map: BTreeMap<&str, i32> = ["Alice", "Bob", "Carol", "Cheryl"].iter()
Expand All @@ -782,9 +778,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// println!("{} => {}", name, balance);
/// }
/// ```
#[unstable(feature = "btree_range",
reason = "matches collection reform specification, waiting for dust to settle",
issue = "27787")]
#[stable(feature = "btree_range", since = "1.17.0")]
pub fn range_mut<T: ?Sized, R>(&mut self, range: R) -> RangeMut<K, V>
where T: Ord, K: Borrow<T>, R: RangeArgument<T>
{
Expand Down
7 changes: 2 additions & 5 deletions src/libcollections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub struct IntoIter<T> {
/// [`BTreeSet`]: struct.BTreeSet.html
/// [`range`]: struct.BTreeSet.html#method.range
#[derive(Debug)]
#[stable(feature = "btree_range", since = "1.17.0")]
pub struct Range<'a, T: 'a> {
iter: ::btree_map::Range<'a, T, ()>,
}
Expand Down Expand Up @@ -264,8 +265,6 @@ impl<T: Ord> BTreeSet<T> {
/// # Examples
///
/// ```
/// #![feature(btree_range, collections_bound)]
///
/// use std::collections::BTreeSet;
/// use std::collections::Bound::Included;
///
Expand All @@ -278,9 +277,7 @@ impl<T: Ord> BTreeSet<T> {
/// }
/// assert_eq!(Some(&5), set.range(4..).next());
/// ```
#[unstable(feature = "btree_range",
reason = "matches collection reform specification, waiting for dust to settle",
issue = "27787")]
#[stable(feature = "btree_range", since = "1.17.0")]
pub fn range<K: ?Sized, R>(&self, range: R) -> Range<T>
where K: Ord, T: Borrow<K>, R: RangeArgument<K>
{
Expand Down
5 changes: 4 additions & 1 deletion src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,17 @@ mod std {
}

/// An endpoint of a range of keys.
#[unstable(feature = "collections_bound", issue = "27787")]
#[stable(feature = "collections_bound", since = "1.17.0")]
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
pub enum Bound<T> {
/// An inclusive bound.
#[stable(feature = "collections_bound", since = "1.17.0")]
Included(T),
/// An exclusive bound.
#[stable(feature = "collections_bound", since = "1.17.0")]
Excluded(T),
/// An infinite endpoint. Indicates that there is no bound in this direction.
#[stable(feature = "collections_bound", since = "1.17.0")]
Unbounded,
}

Expand Down
Loading