mirror of
https://github.com/ValveSoftware/GameNetworkingSockets.git
synced 2026-05-29 16:20:34 +00:00
Promote likely()/unlikely() to public header.
I have been using this in the relay to optimize some branches in inner loop code, and I want to do that more broadly. This is an idiom from the linux kernel.
This commit is contained in:
@@ -107,6 +107,24 @@ struct iovec
|
||||
struct iovec;
|
||||
#endif
|
||||
|
||||
// likely() and unlikely(). Branch hints
|
||||
// This is an idiom from the linux kernel
|
||||
#ifdef __GNUC__
|
||||
#ifndef likely
|
||||
#define likely(x) __builtin_expect (!!(x), 1)
|
||||
#endif
|
||||
#ifndef unlikely
|
||||
#define unlikely(x) __builtin_expect (!!(x), 0)
|
||||
#endif
|
||||
#else
|
||||
#ifndef likely
|
||||
#define likely(x) (x)
|
||||
#endif
|
||||
#ifndef unlikely
|
||||
#define unlikely(x) (x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Internal stuff goes in a private namespace
|
||||
namespace SteamNetworkingSocketsLib {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user