Re: [hackers] [libgrapheme] Mark likely branches || Laslo Hunhold

From: NRK <nrk_AT_disroot.org>
Date: Wed, 5 Jan 2022 02:24:01 +0600

On Wed, Jan 05, 2022 at 01:56:26AM +0600, NRK wrote:
> Just curious, why not use:
>
> #if defined(__has_builtin) && __has_builtin(__builtin_expect)
> #define likely(expr) __builtin_expect(!!(expr), 1)
> #define unlikely(expr) __builtin_expect(!!(expr), 0)
> #else
> #define likely(expr) (expr)
> #define unlikely(expr) (expr)
> #endif

Answering my own question: because it fails if `__has_builtin` is not
defined. I was expecting the 2nd expression wouldn't get evaluated at
all. Should probably take some time and learn more about the
pre-processor sometimes.

- NRK
Received on Tue Jan 04 2022 - 21:24:01 CET

This archive was generated by hypermail 2.3.0 : Tue Jan 04 2022 - 21:24:37 CET