rust/library/core/src/slice
bors 90c02c1bc1 Auto merge of #111296 - Sp00ph:const_gcd, r=nagisa,Mark-Simulacrum
Always const-evaluate the GCD in `slice::align_to_offsets`

Use an inline `const`-block to force the compiler to calculate the GCD at compile time, even in debug mode. This shouldn't affect the behavior of the program at all, but it drastically cuts down on the number of instructions emitted with optimizations disabled.

With the current implementation, a single `slice::align_to` instantiation (specifically `<[u8]>::align_to::<u128>()`) generates 676 instructions (on x86-64). Forcing the GCD computation to be const cuts it down to 327 instructions, so just over 50% less. This is obviously not representative of actual runtime gains, but I still see it as a significant win as long as it doesn't degrade compile times.

Not having to worry about LLVM const-evaluating the GCD function also allows it to use the textbook recursive euclidean algorithm instead of a much more complicated iterative implementation with multiple `unsafe`-blocks.
2023-05-08 23:47:39 +00:00
..
iter replace version placeholders 2023-04-28 08:47:55 -07:00
ascii.rs Tune the is_ascii implementation used for short slices 2023-05-06 22:56:43 -07:00
cmp.rs Merge two different equality specialization traits in core 2023-03-01 14:42:06 -08:00
index.rs rm const traits in libcore 2023-04-16 06:49:27 +00:00
iter.rs Improve internal field comments on slice::Iter(Mut) 2023-04-29 12:50:53 -07:00
memchr.rs fix tidy 2023-04-16 07:27:28 +00:00
mod.rs Auto merge of #111296 - Sp00ph:const_gcd, r=nagisa,Mark-Simulacrum 2023-05-08 23:47:39 +00:00
raw.rs Print the precondition we violated, and visible through output capture 2022-10-26 22:09:17 -04:00
rotate.rs Make ZST checks in core/alloc more readable 2022-09-22 23:12:29 -07:00
sort.rs Fix no_global_oom_handling build 2023-04-21 10:45:06 -05:00
specialize.rs Remove size_of == 1 case from fill specialization. 2021-08-09 19:25:28 +02:00