mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 17:28:30 +00:00
AK: Add Checked::addition_would_overflow()
And switch the two-argument version of Checked::multiplication_would_overflow() to use __builtin_mul_overflow_p(). This helps GCC optimize the code better.
This commit is contained in:
committed by
Andreas Kling
parent
1b36ddce1d
commit
361a1b54d7
11
AK/Checked.h
11
AK/Checked.h
@@ -234,13 +234,16 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename U, typename V>
|
||||||
|
static bool addition_would_overflow(U u, V v)
|
||||||
|
{
|
||||||
|
return __builtin_add_overflow_p(u, v, (T)0);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename U, typename V, typename X>
|
template<typename U, typename V, typename X>
|
||||||
static bool multiplication_would_overflow(U u, V v)
|
static bool multiplication_would_overflow(U u, V v)
|
||||||
{
|
{
|
||||||
Checked checked;
|
return __builtin_mul_overflow_p(u, v, (T)0);
|
||||||
checked = u;
|
|
||||||
checked *= v;
|
|
||||||
return checked.has_overflow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename V, typename X>
|
template<typename U, typename V, typename X>
|
||||||
|
|||||||
Reference in New Issue
Block a user