[algs] Use __builtin_mul_overflow

Compiles to smaller binary.
This commit is contained in:
Behdad Esfahbod 2022-11-21 12:47:53 -07:00
parent a10cfe3f32
commit 25adbb3825
1 changed files with 5 additions and 1 deletions

View File

@ -853,10 +853,14 @@ hb_in_ranges (T u, T lo1, T hi1, Ts... ds)
* Overflow checking. * Overflow checking.
*/ */
/* Consider __builtin_mul_overflow use here also */
static inline bool static inline bool
hb_unsigned_mul_overflows (unsigned int count, unsigned int size) hb_unsigned_mul_overflows (unsigned int count, unsigned int size)
{ {
#if (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__)
unsigned result;
return __builtin_mul_overflow (count, size, &result);
#endif
return (size > 0) && (count >= ((unsigned int) -1) / size); return (size > 0) && (count >= ((unsigned int) -1) / size);
} }