diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/c.h | 30 | ||||
-rw-r--r-- | src/include/utils/pg_locale.h | 4 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/include/c.h b/src/include/c.h index 04fd23577de..6d4495bdd9f 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -333,6 +333,36 @@ #endif /* + * pg_assume(expr) states that we assume `expr` to evaluate to true. In assert + * enabled builds pg_assume() is turned into an assertion, in optimized builds + * we try to clue the compiler into the fact that `expr` is true. + * + * This is useful for two purposes: + * + * 1) Avoid compiler warnings by telling the compiler about assumptions the + * code makes. This is particularly useful when building with optimizations + * and w/o assertions. + * + * 2) Help the compiler to generate more efficient code + * + * It is unspecified whether `expr` is evaluated, therefore it better be + * side-effect free. + */ +#if defined(USE_ASSERT_CHECKING) +#define pg_assume(expr) Assert(expr) +#elif defined(HAVE__BUILTIN_UNREACHABLE) +#define pg_assume(expr) \ + do { \ + if (!(expr)) \ + __builtin_unreachable(); \ + } while (0) +#elif defined(_MSC_VER) +#define pg_assume(expr) __assume(expr) +#else +#define pg_assume(expr) ((void) 0) +#endif + +/* * Hints to the compiler about the likelihood of a branch. Both likely() and * unlikely() return the boolean value of the contained expression. * diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h index 1cd7c76a0a7..931f5b3b880 100644 --- a/src/include/utils/pg_locale.h +++ b/src/include/utils/pg_locale.h @@ -214,8 +214,8 @@ extern void report_newlocale_failure(const char *localename); /* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */ extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen, - pg_locale_t locale); + locale_t loc); extern size_t char2wchar(wchar_t *to, size_t tolen, - const char *from, size_t fromlen, pg_locale_t locale); + const char *from, size_t fromlen, locale_t loc); #endif /* _PG_LOCALE_ */ |