rust/src/libcore
bors 95979dcfb2 Auto merge of #51601 - Emerentius:step_by_range_diet, r=sfackler
Specialize StepBy<Range(Inclusive)>

Part of #51557, related to #43064, #31155

As discussed in the above issues, `step_by` optimizes very badly on ranges which is related to
1. the special casing of the first `StepBy::next()` call
2. the need to do 2 additions of `n - 1` and `1` inside the range's `next()`

This PR eliminates both by overriding `next()` to always produce the current element and also step ahead by `n` elements in one go. The generated code is much better, even identical in the case of a `Range` with constant `start` and `end` where `start+step` can't overflow. Without constant bounds it's a bit longer than the manual loop. `RangeInclusive` doesn't optimize as nicely but is still much better than the original asm.
Unsigned integers optimize better than signed ones for some reason.

See the following two links for a comparison.

[godbolt: specialization for ..](https://godbolt.org/g/haHLJr)
[godbolt: specialization for ..=](https://godbolt.org/g/ewyMu6)

`RangeFrom`, the only other range with an `Iterator` implementation can't be specialized like this without changing behaviour due to overflow. There is no way to save "finished-ness".

The approach can not be used in general, because it would produce side effects of the underlying iterator too early.

May obsolete #51435, haven't checked.
2018-06-21 08:55:13 +00:00
..
benches Move deny(warnings) into rustbuild 2018-04-08 16:59:14 -06:00
char mod.rs isn't beautiful 2018-05-30 22:24:24 +03:00
fmt Reexport fmt::Alignment into std 2018-06-03 17:04:48 +02:00
hash impl Hash for ! 2018-06-14 23:26:38 -04:00
iter specialize StepBy<Range(Inclusive)> 2018-06-19 19:33:54 +02:00
num add some docs to conversions 2018-06-10 13:16:34 +02:00
ops stabilize RangeBounds collections_range #30877 2018-05-24 05:01:40 -07:00
prelude Switch to 1.26 bootstrap compiler 2018-05-17 08:47:25 -06:00
slice Be more precise about why references need to be non-null and aligned 2018-06-09 10:40:51 +02:00
str impl Default for &mut str 2018-06-03 00:29:50 +08:00
sync Auto merge of #48553 - seanmonstar:atomic-debug, r=alexcrichton 2018-04-19 23:08:16 +00:00
tests Auto merge of #51601 - Emerentius:step_by_range_diet, r=sfackler 2018-06-21 08:55:13 +00:00
unicode Regenerate character tables for Unicode 11 2018-06-11 10:54:30 -07:00
alloc.rs Rename OOM to allocation error 2018-06-18 21:41:24 +02:00
any.rs Fix up Any doc examples 2018-05-31 13:27:08 -07:00
array.rs Revert "Stabilize the TryFrom and TryInto traits" 2018-04-20 18:10:00 +02:00
ascii.rs Correct a few stability attributes 2018-04-05 15:39:29 +01:00
borrow.rs Fix formatting. 2018-03-18 13:05:00 +01:00
Cargo.toml Switch to 1.26 bootstrap compiler 2018-05-17 08:47:25 -06:00
cell.rs Add Ref/RefMut map_split method 2018-06-13 11:35:39 -07:00
clone.rs Switch to 1.26 bootstrap compiler 2018-05-17 08:47:25 -06:00
cmp.rs Add more doc aliases 2018-04-26 12:56:10 +02:00
convert.rs Revert "Stabilize the TryFrom and TryInto traits" 2018-04-20 18:10:00 +02:00
default.rs Fix "Quasi-quoting is inefficient" warning in incremental rustbuild. 2017-07-18 01:49:40 +08:00
future.rs add a few blanket future impls to std 2018-06-08 17:56:59 -04:00
hint.rs Stabilize core::hint::unreachable_unchecked. 2018-04-16 18:29:40 +08:00
internal_macros.rs Switch to 1.26 bootstrap compiler 2018-05-17 08:47:25 -06:00
intrinsics.rs Update nomicon link in transmute docs 2018-05-25 11:47:48 -07:00
iter_private.rs Various fixes to wording consistency in the docs 2017-03-22 17:19:52 +01:00
lib.rs Stabilize #[repr(transparent)] 2018-06-12 06:49:07 +02:00
macros.rs undo payload in core::panic! changes 2018-06-03 13:46:19 +02:00
marker.rs Replace if with if and only if in the definition dox of Sync 2018-06-01 09:37:05 +08:00
mem.rs Document size_of for 128-bit integers 2018-06-08 19:20:28 +00:00
nonzero.rs Make core::nonzero private 2018-05-16 19:08:41 +02:00
option.rs Add Option::as_pin_mut 2018-05-22 17:24:49 -07:00
panic.rs implement #[panic_implementation] 2018-06-03 13:46:19 +02:00
panicking.rs undo payload in core::panic! changes 2018-06-03 13:46:19 +02:00
ptr.rs Remove alloc::Opaque and use *mut u8 as pointer type for GlobalAlloc 2018-06-11 13:47:23 -07:00
raw.rs Fix up various links 2017-03-20 10:10:16 -04:00
result.rs Add explanation for #[must_use] on Result 2018-05-07 10:26:28 -07:00
task.rs Improve core::task::TaskObj 2018-06-13 09:32:59 +02:00
time.rs Rollup merge of #50167 - fintelia:duration-nanos, r=sfackler 2018-06-02 13:14:22 -06:00
tuple.rs Update bootstrap compiler 2017-08-31 06:58:58 -07:00
unit.rs impl FromIterator<()> for () 2017-10-18 23:12:37 -07:00