From 7e09d1f94f698d564186e41ec5baa99294357f37 Mon Sep 17 00:00:00 2001 From: hanyunqi Date: Thu, 8 Dec 2016 18:47:01 +0800 Subject: [PATCH] Update shared_func.c update is_power2: return ((n != 0) && !(n & (n - 1))); --- src/shared_func.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/shared_func.c b/src/shared_func.c index 319031d..763a572 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -2306,17 +2306,9 @@ int64_t get_current_time_us() return ((int64_t)tv.tv_sec * 1000 * 1000 + (int64_t)tv.tv_usec); } -bool is_power2(const int64_t n) +inline bool is_power2(const int64_t n) { - int64_t i; - - i = 2; - while (i < n) - { - i *= 2; - } - - return i == n; + return ((n != 0) && !(n & (n - 1))); } static inline int do_lock_file(int fd, int cmd, int type)