From 25adbb382535de2c981755df211295249a93c4e2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 21 Nov 2022 12:47:53 -0700 Subject: [PATCH] [algs] Use __builtin_mul_overflow Compiles to smaller binary. --- src/hb-algs.hh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index bcd7ad059..9659d6330 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -853,10 +853,14 @@ hb_in_ranges (T u, T lo1, T hi1, Ts... ds) * Overflow checking. */ -/* Consider __builtin_mul_overflow use here also */ static inline bool 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); }