From 3a2c9a36b2aaba559541b579dcdf70f38302035a Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Sat, 21 Feb 2026 13:26:55 +0100 Subject: [PATCH] refactor: introduce `is_negative_or_typemax` Results in decreased generated code size (`code_llvm` and `code_native`). --- src/CheckedSizeProduct.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/CheckedSizeProduct.jl b/src/CheckedSizeProduct.jl index b4ad1ba..da49902 100644 --- a/src/CheckedSizeProduct.jl +++ b/src/CheckedSizeProduct.jl @@ -81,16 +81,18 @@ module CheckedSizeProduct x == typemax(x) end + function is_negative_or_typemax(x) + is_negative(x) | is_typemax(x) + end + function typeassert_bool(x::Bool) x end function checked_size_product(t::NonemptyNTuple) any_is_zero = any(typeassert_bool ∘ iszero, t) - any_is_negative = any(typeassert_bool ∘ is_negative, t) - any_is_typemax = any(typeassert_bool ∘ is_typemax, t) + any_is_invalid = any(typeassert_bool ∘ is_negative_or_typemax, t) (product, have_overflow) = checked_dims(t) - any_is_invalid = any_is_negative | any_is_typemax is_not_representable = have_overflow & !any_is_zero if any_is_invalid | is_not_representable nothing