diff options
| author | Emerentius <emerentius@arcor.de> | 2018-06-16 21:58:28 +0200 |
|---|---|---|
| committer | Emerentius <emerentius@arcor.de> | 2018-06-19 19:33:54 +0200 |
| commit | 000aff604e3b16ffc3771bd5d93a6e7b425852d2 (patch) | |
| tree | 3bd5ca2639264c835fe5e39bea26d95a687e475a /src/libcore/tests | |
| parent | 61ba0180933485cf8a2bc6b7230a4c70b82bb063 (diff) | |
| download | rust-000aff604e3b16ffc3771bd5d93a6e7b425852d2.tar.gz rust-000aff604e3b16ffc3771bd5d93a6e7b425852d2.zip | |
specialize StepBy<Range(Inclusive)>
the originally generated code was highly suboptimal this brings it close to the same code or even exactly the same as a manual while-loop by eliminating a branch and the double stepping of n-1 + 1 steps The intermediate trait lets us circumvent the specialization type inference bugs
Diffstat (limited to 'src/libcore/tests')
| -rw-r--r-- | src/libcore/tests/iter.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index 9b8d7031f8e..72b115f8b5f 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -1619,6 +1619,14 @@ fn test_range_step() { } #[test] +fn test_range_inclusive_step() { + assert_eq!((0..=50).step_by(10).collect::<Vec<_>>(), [0, 10, 20, 30, 40, 50]); + assert_eq!((0..=5).step_by(1).collect::<Vec<_>>(), [0, 1, 2, 3, 4, 5]); + assert_eq!((200..=255u8).step_by(10).collect::<Vec<_>>(), [200, 210, 220, 230, 240, 250]); + assert_eq!((250..=255u8).step_by(1).collect::<Vec<_>>(), [250, 251, 252, 253, 254, 255]); +} + +#[test] fn test_range_last_max() { assert_eq!((0..20).last(), Some(19)); assert_eq!((-20..0).last(), Some(-1)); |
