[systemd-devel] [PATCH] journal: u64log2 can be expressed just as __builtin_clzll(n) ^ 63U

Cristian Rodríguez crrodriguez at opensuse.org
Thu Apr 4 16:09:50 PDT 2013


---
 src/journal/journald-rate-limit.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/src/journal/journald-rate-limit.c b/src/journal/journald-rate-limit.c
index 8bd6847..e33b595 100644
--- a/src/journal/journald-rate-limit.c
+++ b/src/journal/journald-rate-limit.c
@@ -170,19 +170,9 @@ fail:
         return NULL;
 }
 
-static uint64_t u64log2(uint64_t n) {
-        unsigned r;
-
-        if (n <= 1)
-                return 0;
-
-        r = 0;
-        for (;;) {
-                n = n >> 1;
-                if (!n)
-                        return r;
-                r++;
-        }
+static inline unsigned u64log2(uint64_t n) {
+
+        return (n > 1) ? __builtin_clzll(n) ^ 63U : 0;
 }
 
 static unsigned burst_modulate(unsigned burst, uint64_t available) {
-- 
1.8.1.4



More information about the systemd-devel mailing list