mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-02 04:20:28 +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:
parent
1b36ddce1d
commit
361a1b54d7
Notes:
sideshowbarker
2024-07-19 07:09:47 +09:00
Author: https://github.com/bugaevc Commit: https://github.com/SerenityOS/serenity/commit/361a1b54d75 Pull-request: https://github.com/SerenityOS/serenity/pull/2024 Reviewed-by: https://github.com/awesomekling
1 changed files with 7 additions and 4 deletions
11
AK/Checked.h
11
AK/Checked.h
|
@ -234,13 +234,16 @@ public:
|
|||
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>
|
||||
static bool multiplication_would_overflow(U u, V v)
|
||||
{
|
||||
Checked checked;
|
||||
checked = u;
|
||||
checked *= v;
|
||||
return checked.has_overflow();
|
||||
return __builtin_mul_overflow_p(u, v, (T)0);
|
||||
}
|
||||
|
||||
template<typename U, typename V, typename X>
|
||||
|
|
Loading…
Reference in a new issue