Skip to content

Commit 59ec9bf

Browse files
committed
Auto merge of #49406 - kennytm:rollup, r=kennytm
Rollup of 11 pull requests - Successful merges: #48639, #49223, #49333, #49369, #49381, #49395, #49399, #49401, #49417, #49202, #49426 - Failed merges:
2 parents 9c9424d + 605ea7c commit 59ec9bf

File tree

27 files changed

+253
-126
lines changed

27 files changed

+253
-126
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ If you're looking for somewhere to start, check out the [E-easy][eeasy] tag.
594594
[inom]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AI-nominated
595595
[eeasy]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AE-easy
596596
[lru]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc
597-
[rfcbot]: https://github.com/dikaiosune/rust-dashboard/blob/master/RFCBOT.md
597+
[rfcbot]: https://github.com/anp/rfcbot-rs/
598598

599599
## Out-of-tree Contributions
600600
[out-of-tree-contributions]: #out-of-tree-contributions

RELEASES.md

+14
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ Compatibility Notes
9898
[`ptr::NonNull`]: https://doc.rust-lang.org/std/ptr/struct.NonNull.html
9999

100100

101+
Version 1.24.1 (2018-03-01)
102+
==========================
103+
104+
- [Do not abort when unwinding through FFI][48251]
105+
- [Emit UTF-16 files for linker arguments on Windows][48318]
106+
- [Make the error index generator work again][48308]
107+
- [Cargo will warn on Windows 7 if an update is needed][cargo/5069].
108+
109+
[48251]: https://github.com/rust-lang/rust/issues/48251
110+
[48308]: https://github.com/rust-lang/rust/issues/48308
111+
[48318]: https://github.com/rust-lang/rust/issues/48318
112+
[cargo/5069]: https://github.com/rust-lang/cargo/pull/5069
113+
114+
101115
Version 1.24.0 (2018-02-15)
102116
==========================
103117

src/Cargo.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/liballoc/benches/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![cfg_attr(stage0, feature(i128_type))]
1414
#![feature(rand)]
1515
#![feature(repr_simd)]
16+
#![feature(slice_sort_by_cached_key)]
1617
#![feature(test)]
1718

1819
extern crate rand;

src/liballoc/benches/slice.rs

+15
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,17 @@ macro_rules! sort_expensive {
284284
}
285285
}
286286

287+
macro_rules! sort_lexicographic {
288+
($f:ident, $name:ident, $gen:expr, $len:expr) => {
289+
#[bench]
290+
fn $name(b: &mut Bencher) {
291+
let v = $gen($len);
292+
b.iter(|| v.clone().$f(|x| x.to_string()));
293+
b.bytes = $len * mem::size_of_val(&$gen(1)[0]) as u64;
294+
}
295+
}
296+
}
297+
287298
sort!(sort, sort_small_ascending, gen_ascending, 10);
288299
sort!(sort, sort_small_descending, gen_descending, 10);
289300
sort!(sort, sort_small_random, gen_random, 10);
@@ -312,6 +323,10 @@ sort!(sort_unstable, sort_unstable_large_big, gen_big_random, 10000);
312323
sort_strings!(sort_unstable, sort_unstable_large_strings, gen_strings, 10000);
313324
sort_expensive!(sort_unstable_by, sort_unstable_large_expensive, gen_random, 10000);
314325

326+
sort_lexicographic!(sort_by_key, sort_by_key_lexicographic, gen_random, 10000);
327+
sort_lexicographic!(sort_unstable_by_key, sort_unstable_by_key_lexicographic, gen_random, 10000);
328+
sort_lexicographic!(sort_by_cached_key, sort_by_cached_key_lexicographic, gen_random, 10000);
329+
315330
macro_rules! reverse {
316331
($name:ident, $ty:ty, $f:expr) => {
317332
#[bench]

src/liballoc/fmt.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
//! sign := '+' | '-'
327327
//! width := count
328328
//! precision := count | '*'
329-
//! type := identifier | ''
329+
//! type := identifier | '?' | ''
330330
//! count := parameter | integer
331331
//! parameter := argument '$'
332332
//! ```
@@ -516,17 +516,17 @@ pub use core::fmt::rt;
516516
#[stable(feature = "rust1", since = "1.0.0")]
517517
pub use core::fmt::{Formatter, Result, Write};
518518
#[stable(feature = "rust1", since = "1.0.0")]
519-
pub use core::fmt::{Octal, Binary};
519+
pub use core::fmt::{Binary, Octal};
520520
#[stable(feature = "rust1", since = "1.0.0")]
521-
pub use core::fmt::{Display, Debug};
521+
pub use core::fmt::{Debug, Display};
522522
#[stable(feature = "rust1", since = "1.0.0")]
523-
pub use core::fmt::{LowerHex, UpperHex, Pointer};
523+
pub use core::fmt::{LowerHex, Pointer, UpperHex};
524524
#[stable(feature = "rust1", since = "1.0.0")]
525525
pub use core::fmt::{LowerExp, UpperExp};
526526
#[stable(feature = "rust1", since = "1.0.0")]
527527
pub use core::fmt::Error;
528528
#[stable(feature = "rust1", since = "1.0.0")]
529-
pub use core::fmt::{ArgumentV1, Arguments, write};
529+
pub use core::fmt::{write, ArgumentV1, Arguments};
530530
#[stable(feature = "rust1", since = "1.0.0")]
531531
pub use core::fmt::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple};
532532

@@ -563,7 +563,8 @@ use string;
563563
pub fn format(args: Arguments) -> string::String {
564564
let capacity = args.estimated_capacity();
565565
let mut output = string::String::with_capacity(capacity);
566-
output.write_fmt(args)
567-
.expect("a formatting trait implementation returned an error");
566+
output
567+
.write_fmt(args)
568+
.expect("a formatting trait implementation returned an error");
568569
output
569570
}

src/liballoc/slice.rs

+78-10
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ use core::mem::size_of;
102102
use core::mem;
103103
use core::ptr;
104104
use core::slice as core_slice;
105+
use core::{u8, u16, u32};
105106

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

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

1339+
/// Sorts the slice with a key extraction function.
1340+
///
1341+
/// During sorting, the key function is called only once per element.
1342+
///
1343+
/// This sort is stable (i.e. does not reorder equal elements) and `O(m n + n log n)`
1344+
/// worst-case, where the key function is `O(m)`.
1345+
///
1346+
/// For simple key functions (e.g. functions that are property accesses or
1347+
/// basic operations), [`sort_by_key`](#method.sort_by_key) is likely to be
1348+
/// faster.
1349+
///
1350+
/// # Current implementation
1351+
///
1352+
/// The current algorithm is based on [pattern-defeating quicksort][pdqsort] by Orson Peters,
1353+
/// which combines the fast average case of randomized quicksort with the fast worst case of
1354+
/// heapsort, while achieving linear time on slices with certain patterns. It uses some
1355+
/// randomization to avoid degenerate cases, but with a fixed seed to always provide
1356+
/// deterministic behavior.
1357+
///
1358+
/// In the worst case, the algorithm allocates temporary storage in a `Vec<(K, usize)>` the
1359+
/// length of the slice.
1360+
///
1361+
/// # Examples
1362+
///
1363+
/// ```
1364+
/// #![feature(slice_sort_by_cached_key)]
1365+
/// let mut v = [-5i32, 4, 32, -3, 2];
1366+
///
1367+
/// v.sort_by_cached_key(|k| k.to_string());
1368+
/// assert!(v == [-3, -5, 2, 32, 4]);
1369+
/// ```
1370+
///
1371+
/// [pdqsort]: https://github.com/orlp/pdqsort
1372+
#[unstable(feature = "slice_sort_by_cached_key", issue = "34447")]
1373+
#[inline]
1374+
pub fn sort_by_cached_key<K, F>(&mut self, f: F)
1375+
where F: FnMut(&T) -> K, K: Ord
1376+
{
1377+
// Helper macro for indexing our vector by the smallest possible type, to reduce allocation.
1378+
macro_rules! sort_by_key {
1379+
($t:ty, $slice:ident, $f:ident) => ({
1380+
let mut indices: Vec<_> =
1381+
$slice.iter().map($f).enumerate().map(|(i, k)| (k, i as $t)).collect();
1382+
// The elements of `indices` are unique, as they are indexed, so any sort will be
1383+
// stable with respect to the original slice. We use `sort_unstable` here because
1384+
// it requires less memory allocation.
1385+
indices.sort_unstable();
1386+
for i in 0..$slice.len() {
1387+
let mut index = indices[i].1;
1388+
while (index as usize) < i {
1389+
index = indices[index as usize].1;
1390+
}
1391+
indices[i].1 = index;
1392+
$slice.swap(i, index as usize);
1393+
}
1394+
})
1395+
}
1396+
1397+
let sz_u8 = mem::size_of::<(K, u8)>();
1398+
let sz_u16 = mem::size_of::<(K, u16)>();
1399+
let sz_u32 = mem::size_of::<(K, u32)>();
1400+
let sz_usize = mem::size_of::<(K, usize)>();
1401+
1402+
let len = self.len();
1403+
if sz_u8 < sz_u16 && len <= ( u8::MAX as usize) { return sort_by_key!( u8, self, f) }
1404+
if sz_u16 < sz_u32 && len <= (u16::MAX as usize) { return sort_by_key!(u16, self, f) }
1405+
if sz_u32 < sz_usize && len <= (u32::MAX as usize) { return sort_by_key!(u32, self, f) }
1406+
sort_by_key!(usize, self, f)
1407+
}
1408+
13371409
/// Sorts the slice, but may not preserve the order of equal elements.
13381410
///
13391411
/// This sort is unstable (i.e. may reorder equal elements), in-place (i.e. does not allocate),
@@ -1410,7 +1482,7 @@ impl<T> [T] {
14101482
/// elements.
14111483
///
14121484
/// This sort is unstable (i.e. may reorder equal elements), in-place (i.e. does not allocate),
1413-
/// and `O(n log n)` worst-case.
1485+
/// and `O(m n log(m n))` worst-case, where the key function is `O(m)`.
14141486
///
14151487
/// # Current implementation
14161488
///
@@ -1420,9 +1492,6 @@ impl<T> [T] {
14201492
/// randomization to avoid degenerate cases, but with a fixed seed to always provide
14211493
/// deterministic behavior.
14221494
///
1423-
/// It is typically faster than stable sorting, except in a few special cases, e.g. when the
1424-
/// slice consists of several concatenated sorted sequences.
1425-
///
14261495
/// # Examples
14271496
///
14281497
/// ```
@@ -1435,9 +1504,8 @@ impl<T> [T] {
14351504
/// [pdqsort]: https://github.com/orlp/pdqsort
14361505
#[stable(feature = "sort_unstable", since = "1.20.0")]
14371506
#[inline]
1438-
pub fn sort_unstable_by_key<B, F>(&mut self, f: F)
1439-
where F: FnMut(&T) -> B,
1440-
B: Ord
1507+
pub fn sort_unstable_by_key<K, F>(&mut self, f: F)
1508+
where F: FnMut(&T) -> K, K: Ord
14411509
{
14421510
core_slice::SliceExt::sort_unstable_by_key(self, f);
14431511
}

src/liballoc/str.rs

+42
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,48 @@ impl str {
21222122
unsafe { String::from_utf8_unchecked(buf) }
21232123
}
21242124

2125+
/// Returns true if this `str` is entirely whitespace, and false otherwise.
2126+
///
2127+
/// 'Whitespace' is defined according to the terms of the Unicode Derived Core
2128+
/// Property `White_Space`.
2129+
///
2130+
/// # Examples
2131+
///
2132+
/// Basic usage:
2133+
///
2134+
/// ```
2135+
/// assert!(" \t ".is_whitespace());
2136+
///
2137+
/// // a non-breaking space
2138+
/// assert!("\u{A0}".is_whitespace());
2139+
///
2140+
/// assert!(!" 越".is_whitespace());
2141+
/// ```
2142+
#[stable(feature = "unicode_methods_on_intrinsics", since = "1.27.0")]
2143+
#[inline]
2144+
pub fn is_whitespace(&self) -> bool {
2145+
UnicodeStr::is_whitespace(self)
2146+
}
2147+
2148+
/// Returns true if this `str` is entirely alphanumeric, and false otherwise.
2149+
///
2150+
/// 'Alphanumeric'-ness is defined in terms of the Unicode General Categories
2151+
/// 'Nd', 'Nl', 'No' and the Derived Core Property 'Alphabetic'.
2152+
///
2153+
/// # Examples
2154+
///
2155+
/// Basic usage:
2156+
///
2157+
/// ```
2158+
/// assert!("٣7৬Kو藏".is_alphanumeric());
2159+
/// assert!(!"¾①".is_alphanumeric());
2160+
/// ```
2161+
#[stable(feature = "unicode_methods_on_intrinsics", since = "1.27.0")]
2162+
#[inline]
2163+
pub fn is_alphanumeric(&self) -> bool {
2164+
UnicodeStr::is_alphanumeric(self)
2165+
}
2166+
21252167
/// Checks if all characters in this string are within the ASCII range.
21262168
///
21272169
/// # Examples

src/liballoc/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![feature(pattern)]
2424
#![feature(placement_in_syntax)]
2525
#![feature(rand)]
26+
#![feature(slice_sort_by_cached_key)]
2627
#![feature(splice)]
2728
#![feature(str_escape)]
2829
#![feature(string_retain)]

0 commit comments

Comments
 (0)