Rollup merge of #146254 - yotamofek:pr/itertools-all-equal-value, r=cjgillot

Use `Itertools::all_equal_value()` where applicable

Just a small cleanup.
We already have `itertools` as a dep in these crates, so might as well use another of its features.
Makes the code simpler IMHO :)
This commit is contained in:
Matthias Krüger
2025-09-07 08:18:59 +02:00
committed by GitHub
5 changed files with 35 additions and 46 deletions

View File

@@ -1,3 +1,4 @@
use itertools::Itertools as _;
use rustc_abi::{self as abi, FIRST_VARIANT};
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout};
@@ -111,14 +112,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let size = bx.const_usize(dest.layout.size.bytes());
// Use llvm.memset.p0i8.* to initialize all same byte arrays
if let Some(int) = bx.cx().const_to_opt_u128(v, false) {
let bytes = &int.to_le_bytes()[..cg_elem.layout.size.bytes_usize()];
let first = bytes[0];
if bytes[1..].iter().all(|&b| b == first) {
let fill = bx.cx().const_u8(first);
bx.memset(start, fill, size, dest.val.align, MemFlags::empty());
return true;
}
if let Some(int) = bx.cx().const_to_opt_u128(v, false)
&& let bytes = &int.to_le_bytes()[..cg_elem.layout.size.bytes_usize()]
&& let Ok(&byte) = bytes.iter().all_equal_value()
{
let fill = bx.cx().const_u8(byte);
bx.memset(start, fill, size, dest.val.align, MemFlags::empty());
return true;
}
// Use llvm.memset.p0i8.* to initialize byte arrays
@@ -130,13 +130,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
false
};
match cg_elem.val {
OperandValue::Immediate(v) => {
if try_init_all_same(bx, v) {
return;
}
}
_ => (),
if let OperandValue::Immediate(v) = cg_elem.val
&& try_init_all_same(bx, v)
{
return;
}
let count = self