From 1265e687ffab6f0afcaff887049199bcd28adaaa Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Sun, 16 May 2021 17:53:45 +0300 Subject: [PATCH] mhd_bithelpers: replaced macro with static function Bit-rotating macro was replaced with static inline function to avoid two time evaluation and calculation of the parameters. --- src/microhttpd/mhd_bithelpers.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/microhttpd/mhd_bithelpers.h b/src/microhttpd/mhd_bithelpers.h index e023bf12..5d1aadef 100644 --- a/src/microhttpd/mhd_bithelpers.h +++ b/src/microhttpd/mhd_bithelpers.h @@ -26,13 +26,14 @@ #ifndef MHD_BITHELPERS_H #define MHD_BITHELPERS_H 1 -#include "mhd_byteorder.h" #include #if defined(_MSC_FULL_VER) && (! defined(__clang__) || (defined(__c2__) && \ defined(__OPTIMIZE__))) /* Declarations for VC & Clang/C2 built-ins */ #include #endif /* _MSC_FULL_VER */ +#include "mhd_assert.h" +#include "mhd_byteorder.h" #ifndef __has_builtin /* Avoid precompiler errors with non-clang */ @@ -230,9 +231,13 @@ #define _MHD_ROTR32(value32, bits) \ ((uint32_t) _rotr ((uint32_t) (value32),(bits))) #else /* ! _MSC_FULL_VER */ -/* Defined in form which modern compiler could optimize. */ -#define _MHD_ROTR32(value32, bits) \ - (((uint32_t) (value32)) >> (bits) | ((uint32_t) (value32)) << (32 - bits)) +_MHD_static_inline uint32_t +_MHD_ROTR32 (uint32_t value32, int bits) +{ + mhd_assert (bits < 32); + /* Defined in form which modern compiler could optimize. */ + return (value32 >> bits) | (value32 << (32 - bits)); +} #endif /* ! _MSC_FULL_VER */