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 (unsupervised) #48689

Merged
merged 25 commits into from
Mar 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0700bd1
Clarify "It is an error to..." wording for zero-duration behaviors.
frewsxcv Feb 18, 2018
0c9afa8
Provide missing comma in match arm suggestion
estebank Feb 18, 2018
ba7039c
Detect missing `if` blocks
estebank Feb 19, 2018
36baa81
Add label to primary span in some parse errors
estebank Feb 19, 2018
d63d363
Diagnostic tweaks (review)
estebank Feb 24, 2018
24be75d
fix rebase
estebank Feb 28, 2018
25b69c4
impl Default + Hash for ::core::cmp::Reverse
strake Mar 1, 2018
70d5a46
Specialize Zip::nth for TrustedRandomAccess
scottmcm Mar 1, 2018
11fefeb
Add a Zip::nth test for side effects
scottmcm Mar 1, 2018
5105fc1
Fix braces
scottmcm Mar 1, 2018
2e9d9d4
rustc: More stable hashes of command line arguments
alexcrichton Mar 1, 2018
1011b8a
Stabilize Unsafe Pointer Methods
tinaun Feb 16, 2018
69c53ac
Run Rustfix on librustc
Manishearth Feb 23, 2018
f3cb962
Perform manual fixups
Manishearth Feb 23, 2018
fb7980d
Remove allow(bare_trait_object) from librustc
Manishearth Feb 23, 2018
8d730ed
Run Rustfix on librustc_mir
Manishearth Feb 23, 2018
3c95814
Perform manual fixups
Manishearth Feb 23, 2018
40f218f
Remove allow(bare_trait_object) from librustc_mir
Manishearth Feb 23, 2018
85a6b92
Rollup merge of #48477 - Manishearth:dyn-trait-fixes, r=nmatsakis
Manishearth Mar 3, 2018
65253fd
Rollup merge of #48259 - tinaun:patch-1, r=alexcrichton
Manishearth Mar 3, 2018
8bf026d
Rollup merge of #48328 - frewsxcv:frewsxcv-clarify-error-zero-duratio…
Manishearth Mar 3, 2018
8c7c8fb
Rollup merge of #48338 - estebank:match-missing-comma, r=petrochenkov
Manishearth Mar 3, 2018
6fa14f0
Rollup merge of #48628 - strake:reverse, r=sfackler
Manishearth Mar 3, 2018
3fa4bff
Rollup merge of #48635 - scottmcm:faster-zip-nth, r=kennytm
Manishearth Mar 3, 2018
40d2a98
Rollup merge of #48641 - alexcrichton:no-hash-l-paths, r=michaelwoeri…
Manishearth Mar 3, 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
29 changes: 29 additions & 0 deletions src/libcore/benches/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,32 @@ bench_sums! {
bench_take_while_chain_ref_sum,
(0i64..1000000).chain(1000000..).take_while(|&x| x < 1111111)
}

// Checks whether Skip<Zip<A,B>> is as fast as Zip<Skip<A>, Skip<B>>, from
// https://users.rust-lang.org/t/performance-difference-between-iterator-zip-and-skip-order/15743
#[bench]
fn bench_zip_then_skip(b: &mut Bencher) {
let v: Vec<_> = (0..100_000).collect();
let t: Vec<_> = (0..100_000).collect();

b.iter(|| {
let s = v.iter().zip(t.iter()).skip(10000)
.take_while(|t| *t.0 < 10100)
.map(|(a, b)| *a + *b)
.sum::<u64>();
assert_eq!(s, 2009900);
});
}
#[bench]
fn bench_skip_then_zip(b: &mut Bencher) {
let v: Vec<_> = (0..100_000).collect();
let t: Vec<_> = (0..100_000).collect();

b.iter(|| {
let s = v.iter().skip(10000).zip(t.iter().skip(10000))
.take_while(|t| *t.0 < 10100)
.map(|(a, b)| *a + *b)
.sum::<u64>();
assert_eq!(s, 2009900);
});
}
2 changes: 1 addition & 1 deletion src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl Ordering {
/// v.sort_by_key(|&num| (num > 3, Reverse(num)));
/// assert_eq!(v, vec![3, 2, 1, 6, 5, 4]);
/// ```
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
#[derive(PartialEq, Eq, Debug, Copy, Clone, Default, Hash)]
#[stable(feature = "reverse_cmp_key", since = "1.19.0")]
pub struct Reverse<T>(#[stable(feature = "reverse_cmp_key", since = "1.19.0")] pub T);

Expand Down
36 changes: 36 additions & 0 deletions src/libcore/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,11 @@ impl<A, B> Iterator for Zip<A, B> where A: Iterator, B: Iterator
fn size_hint(&self) -> (usize, Option<usize>) {
ZipImpl::size_hint(self)
}

#[inline]
fn nth(&mut self, n: usize) -> Option<Self::Item> {
ZipImpl::nth(self, n)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -1065,6 +1070,14 @@ trait ZipImpl<A, B> {
fn new(a: A, b: B) -> Self;
fn next(&mut self) -> Option<Self::Item>;
fn size_hint(&self) -> (usize, Option<usize>);
fn nth(&mut self, n: usize) -> Option<Self::Item>;
fn super_nth(&mut self, mut n: usize) -> Option<Self::Item> {
while let Some(x) = self.next() {
if n == 0 { return Some(x) }
n -= 1;
}
None
}
fn next_back(&mut self) -> Option<Self::Item>
where A: DoubleEndedIterator + ExactSizeIterator,
B: DoubleEndedIterator + ExactSizeIterator;
Expand Down Expand Up @@ -1094,6 +1107,11 @@ impl<A, B> ZipImpl<A, B> for Zip<A, B>
})
}

#[inline]
default fn nth(&mut self, n: usize) -> Option<Self::Item> {
self.super_nth(n)
}

#[inline]
default fn next_back(&mut self) -> Option<(A::Item, B::Item)>
where A: DoubleEndedIterator + ExactSizeIterator,
Expand Down Expand Up @@ -1174,6 +1192,24 @@ impl<A, B> ZipImpl<A, B> for Zip<A, B>
(len, Some(len))
}

#[inline]
fn nth(&mut self, n: usize) -> Option<Self::Item> {
let delta = cmp::min(n, self.len - self.index);
let end = self.index + delta;
while self.index < end {
let i = self.index;
self.index += 1;
if A::may_have_side_effect() {
unsafe { self.a.get_unchecked(i); }
}
if B::may_have_side_effect() {
unsafe { self.b.get_unchecked(i); }
}
}

self.super_nth(n - delta)
}

#[inline]
fn next_back(&mut self) -> Option<(A::Item, B::Item)>
where A: DoubleEndedIterator + ExactSizeIterator,
Expand Down
Loading