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 11 pull requests #49406

Merged
merged 37 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ea6a1bd
Compute each key only one during slice::sort_by_key
varkor Mar 1, 2018
670e69e
Update documentation for sort_by_key
varkor Mar 1, 2018
b8452cc
Clarify behaviour of sort_unstable_by_key with respect to sort_by_key
varkor Mar 1, 2018
9fbee35
Add a test for sort_by_key
varkor Mar 1, 2018
21fde09
Update documentation
varkor Mar 1, 2018
7dcfc07
Cull the quadratic
varkor Mar 2, 2018
bdcc6f9
Index enumeration by minimally sized type
varkor Mar 2, 2018
f41a26f
Add sort_by_cached_key method
varkor Mar 16, 2018
b430cba
Fix use of unstable feature in test
varkor Mar 16, 2018
ca3bed0
Improve and fix documentation for sort_by_cached_key
varkor Mar 17, 2018
9896b38
Clarify time complexity
varkor Mar 17, 2018
81edd17
Check that the size optimisation is not redundant
varkor Mar 18, 2018
785e3c3
Add lexicographic sorting benchmark
varkor Mar 18, 2018
eca1e18
Add stability test for sort_by_cached_key
varkor Mar 19, 2018
1f51840
Propose a variant if it is an enum for E0599
GuillaumeGomez Mar 20, 2018
4083bdf
Fix impl assoc constant link not working
GuillaumeGomez Mar 24, 2018
1e2458e
Add is_whitespace and is_alphanumeric to str.
Mar 26, 2018
5fc7e0a
Remove unnecessary trait import.
Mar 26, 2018
a637dd0
Fix pretty-printing for raw identifiers
petrochenkov Mar 25, 2018
9c7b69e
Remove mentions of unstable sort_by_cached key from stable documentation
varkor Mar 26, 2018
604bbee
libsyntax: Remove obsolete.rs
petrochenkov Mar 26, 2018
0f1c649
Fix diagnostic colors on Windows 10 console.
ehuss Mar 26, 2018
554dd3e
Add missing '?' to format grammar.
Mar 27, 2018
42de36d
Rollup merge of #48639 - varkor:sort_by_key-cached, r=bluss
kennytm Mar 27, 2018
3d910b8
Rollup merge of #49223 - GuillaumeGomez:propose-variant-for-E0599, r=…
kennytm Mar 27, 2018
68a2e73
Rollup merge of #49333 - GuillaumeGomez:link-assoc-const, r=QuietMisd…
kennytm Mar 27, 2018
dbd6c56
Rollup merge of #49369 - petrochenkov:rprint, r=oli-obk
kennytm Mar 27, 2018
1c45f6c
Rollup merge of #49381 - withoutboats:str_unicode, r=SimonSapin
kennytm Mar 27, 2018
6313997
Add back 1.24.1 release notes
WiSaGaN Mar 27, 2018
5eb4689
Rollup merge of #49395 - petrochenkov:obsolete, r=alexcrichton
kennytm Mar 27, 2018
2d05bde
Rollup merge of #49399 - ehuss:termcolor-update, r=alexcrichton
kennytm Mar 27, 2018
b4bc2b0
Rollup merge of #49401 - alercah:format, r=cramertj
kennytm Mar 27, 2018
5b1a600
Update compiler-rt with fix for 32bit iOS ARM
TimNN Mar 27, 2018
0873974
Rollup merge of #49417 - TimNN:fix-ios, r=alexcrichton
kennytm Mar 27, 2018
f513fbd
Update CONTRIBUTING.md
lukaslueg Mar 27, 2018
19fe9d1
Rollup merge of #49407 - WiSaGaN:patch-1, r=alexcrichton
kennytm Mar 27, 2018
605ea7c
Rollup merge of #49426 - lukaslueg:patch-1, r=kennytm
kennytm Mar 27, 2018
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ If you're looking for somewhere to start, check out the [E-easy][eeasy] tag.
[inom]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AI-nominated
[eeasy]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AE-easy
[lru]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc
[rfcbot]: https://github.com/dikaiosune/rust-dashboard/blob/master/RFCBOT.md
[rfcbot]: https://github.com/anp/rfcbot-rs/

## Out-of-tree Contributions
[out-of-tree-contributions]: #out-of-tree-contributions
Expand Down
14 changes: 14 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ Compatibility Notes
[`ptr::NonNull`]: https://doc.rust-lang.org/std/ptr/struct.NonNull.html


Version 1.24.1 (2018-03-01)
==========================

- [Do not abort when unwinding through FFI][48251]
- [Emit UTF-16 files for linker arguments on Windows][48318]
- [Make the error index generator work again][48308]
- [Cargo will warn on Windows 7 if an update is needed][cargo/5069].

[48251]: https://github.com/rust-lang/rust/issues/48251
[48308]: https://github.com/rust-lang/rust/issues/48308
[48318]: https://github.com/rust-lang/rust/issues/48318
[cargo/5069]: https://github.com/rust-lang/cargo/pull/5069


Version 1.24.0 (2018-02-15)
==========================

Expand Down
12 changes: 6 additions & 6 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/liballoc/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#![cfg_attr(stage0, feature(i128_type))]
#![feature(rand)]
#![feature(repr_simd)]
#![feature(slice_sort_by_cached_key)]
#![feature(test)]

extern crate rand;
Expand Down
15 changes: 15 additions & 0 deletions src/liballoc/benches/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,17 @@ macro_rules! sort_expensive {
}
}

macro_rules! sort_lexicographic {
($f:ident, $name:ident, $gen:expr, $len:expr) => {
#[bench]
fn $name(b: &mut Bencher) {
let v = $gen($len);
b.iter(|| v.clone().$f(|x| x.to_string()));
b.bytes = $len * mem::size_of_val(&$gen(1)[0]) as u64;
}
}
}

sort!(sort, sort_small_ascending, gen_ascending, 10);
sort!(sort, sort_small_descending, gen_descending, 10);
sort!(sort, sort_small_random, gen_random, 10);
Expand Down Expand Up @@ -312,6 +323,10 @@ sort!(sort_unstable, sort_unstable_large_big, gen_big_random, 10000);
sort_strings!(sort_unstable, sort_unstable_large_strings, gen_strings, 10000);
sort_expensive!(sort_unstable_by, sort_unstable_large_expensive, gen_random, 10000);

sort_lexicographic!(sort_by_key, sort_by_key_lexicographic, gen_random, 10000);
sort_lexicographic!(sort_unstable_by_key, sort_unstable_by_key_lexicographic, gen_random, 10000);
sort_lexicographic!(sort_by_cached_key, sort_by_cached_key_lexicographic, gen_random, 10000);

macro_rules! reverse {
($name:ident, $ty:ty, $f:expr) => {
#[bench]
Expand Down
15 changes: 8 additions & 7 deletions src/liballoc/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@
//! sign := '+' | '-'
//! width := count
//! precision := count | '*'
//! type := identifier | ''
//! type := identifier | '?' | ''
//! count := parameter | integer
//! parameter := argument '$'
//! ```
Expand Down Expand Up @@ -516,17 +516,17 @@ pub use core::fmt::rt;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::{Formatter, Result, Write};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::{Octal, Binary};
pub use core::fmt::{Binary, Octal};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::{Display, Debug};
pub use core::fmt::{Debug, Display};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::{LowerHex, UpperHex, Pointer};
pub use core::fmt::{LowerHex, Pointer, UpperHex};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::{LowerExp, UpperExp};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::Error;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::{ArgumentV1, Arguments, write};
pub use core::fmt::{write, ArgumentV1, Arguments};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple};

Expand Down Expand Up @@ -563,7 +563,8 @@ use string;
pub fn format(args: Arguments) -> string::String {
let capacity = args.estimated_capacity();
let mut output = string::String::with_capacity(capacity);
output.write_fmt(args)
.expect("a formatting trait implementation returned an error");
output
.write_fmt(args)
.expect("a formatting trait implementation returned an error");
output
}
88 changes: 78 additions & 10 deletions src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ use core::mem::size_of;
use core::mem;
use core::ptr;
use core::slice as core_slice;
use core::{u8, u16, u32};

use borrow::{Borrow, BorrowMut, ToOwned};
use boxed::Box;
Expand Down Expand Up @@ -1302,7 +1303,8 @@ impl<T> [T] {

/// Sorts the slice with a key extraction function.
///
/// This sort is stable (i.e. does not reorder equal elements) and `O(n log n)` worst-case.
/// This sort is stable (i.e. does not reorder equal elements) and `O(m n log(m n))`
/// worst-case, where the key function is `O(m)`.
///
/// When applicable, unstable sorting is preferred because it is generally faster than stable
/// sorting and it doesn't allocate auxiliary memory.
Expand All @@ -1328,12 +1330,82 @@ impl<T> [T] {
/// ```
#[stable(feature = "slice_sort_by_key", since = "1.7.0")]
#[inline]
pub fn sort_by_key<B, F>(&mut self, mut f: F)
where F: FnMut(&T) -> B, B: Ord
pub fn sort_by_key<K, F>(&mut self, mut f: F)
where F: FnMut(&T) -> K, K: Ord
{
merge_sort(self, |a, b| f(a).lt(&f(b)));
}

/// Sorts the slice with a key extraction function.
///
/// During sorting, the key function is called only once per element.
///
/// This sort is stable (i.e. does not reorder equal elements) and `O(m n + n log n)`
/// worst-case, where the key function is `O(m)`.
///
/// For simple key functions (e.g. functions that are property accesses or
/// basic operations), [`sort_by_key`](#method.sort_by_key) is likely to be
/// faster.
///
/// # Current implementation
///
/// The current algorithm is based on [pattern-defeating quicksort][pdqsort] by Orson Peters,
/// which combines the fast average case of randomized quicksort with the fast worst case of
/// heapsort, while achieving linear time on slices with certain patterns. It uses some
/// randomization to avoid degenerate cases, but with a fixed seed to always provide
/// deterministic behavior.
///
/// In the worst case, the algorithm allocates temporary storage in a `Vec<(K, usize)>` the
/// length of the slice.
///
/// # Examples
///
/// ```
/// #![feature(slice_sort_by_cached_key)]
/// let mut v = [-5i32, 4, 32, -3, 2];
///
/// v.sort_by_cached_key(|k| k.to_string());
/// assert!(v == [-3, -5, 2, 32, 4]);
/// ```
///
/// [pdqsort]: https://github.com/orlp/pdqsort
#[unstable(feature = "slice_sort_by_cached_key", issue = "34447")]
#[inline]
pub fn sort_by_cached_key<K, F>(&mut self, f: F)
where F: FnMut(&T) -> K, K: Ord
{
// Helper macro for indexing our vector by the smallest possible type, to reduce allocation.
macro_rules! sort_by_key {
($t:ty, $slice:ident, $f:ident) => ({
let mut indices: Vec<_> =
$slice.iter().map($f).enumerate().map(|(i, k)| (k, i as $t)).collect();
// The elements of `indices` are unique, as they are indexed, so any sort will be
// stable with respect to the original slice. We use `sort_unstable` here because
// it requires less memory allocation.
indices.sort_unstable();
for i in 0..$slice.len() {
let mut index = indices[i].1;
while (index as usize) < i {
index = indices[index as usize].1;
}
indices[i].1 = index;
$slice.swap(i, index as usize);
}
})
}

let sz_u8 = mem::size_of::<(K, u8)>();
let sz_u16 = mem::size_of::<(K, u16)>();
let sz_u32 = mem::size_of::<(K, u32)>();
let sz_usize = mem::size_of::<(K, usize)>();

let len = self.len();
if sz_u8 < sz_u16 && len <= ( u8::MAX as usize) { return sort_by_key!( u8, self, f) }
if sz_u16 < sz_u32 && len <= (u16::MAX as usize) { return sort_by_key!(u16, self, f) }
if sz_u32 < sz_usize && len <= (u32::MAX as usize) { return sort_by_key!(u32, self, f) }
sort_by_key!(usize, self, f)
}

/// Sorts the slice, but may not preserve the order of equal elements.
///
/// This sort is unstable (i.e. may reorder equal elements), in-place (i.e. does not allocate),
Expand Down Expand Up @@ -1410,7 +1482,7 @@ impl<T> [T] {
/// elements.
///
/// This sort is unstable (i.e. may reorder equal elements), in-place (i.e. does not allocate),
/// and `O(n log n)` worst-case.
/// and `O(m n log(m n))` worst-case, where the key function is `O(m)`.
///
/// # Current implementation
///
Expand All @@ -1420,9 +1492,6 @@ impl<T> [T] {
/// randomization to avoid degenerate cases, but with a fixed seed to always provide
/// deterministic behavior.
///
/// It is typically faster than stable sorting, except in a few special cases, e.g. when the
/// slice consists of several concatenated sorted sequences.
///
/// # Examples
///
/// ```
Expand All @@ -1435,9 +1504,8 @@ impl<T> [T] {
/// [pdqsort]: https://github.com/orlp/pdqsort
#[stable(feature = "sort_unstable", since = "1.20.0")]
#[inline]
pub fn sort_unstable_by_key<B, F>(&mut self, f: F)
where F: FnMut(&T) -> B,
B: Ord
pub fn sort_unstable_by_key<K, F>(&mut self, f: F)
where F: FnMut(&T) -> K, K: Ord
{
core_slice::SliceExt::sort_unstable_by_key(self, f);
}
Expand Down
42 changes: 42 additions & 0 deletions src/liballoc/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2122,6 +2122,48 @@ impl str {
unsafe { String::from_utf8_unchecked(buf) }
}

/// Returns true if this `str` is entirely whitespace, and false otherwise.
///
/// 'Whitespace' is defined according to the terms of the Unicode Derived Core
/// Property `White_Space`.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// assert!(" \t ".is_whitespace());
///
/// // a non-breaking space
/// assert!("\u{A0}".is_whitespace());
///
/// assert!(!" 越".is_whitespace());
/// ```
#[stable(feature = "unicode_methods_on_intrinsics", since = "1.27.0")]
#[inline]
pub fn is_whitespace(&self) -> bool {
UnicodeStr::is_whitespace(self)
}

/// Returns true if this `str` is entirely alphanumeric, and false otherwise.
///
/// 'Alphanumeric'-ness is defined in terms of the Unicode General Categories
/// 'Nd', 'Nl', 'No' and the Derived Core Property 'Alphabetic'.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// assert!("٣7৬Kو藏".is_alphanumeric());
/// assert!(!"¾①".is_alphanumeric());
/// ```
#[stable(feature = "unicode_methods_on_intrinsics", since = "1.27.0")]
#[inline]
pub fn is_alphanumeric(&self) -> bool {
UnicodeStr::is_alphanumeric(self)
}

/// Checks if all characters in this string are within the ASCII range.
///
/// # Examples
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#![feature(pattern)]
#![feature(placement_in_syntax)]
#![feature(rand)]
#![feature(slice_sort_by_cached_key)]
#![feature(splice)]
#![feature(str_escape)]
#![feature(string_retain)]
Expand Down
Loading