From af31012815e20f0c92ed6ea803638a16ba47b0c2 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Thu, 21 Jun 2018 16:40:02 +0300 Subject: [PATCH] More effective implementation of nxt_popcount(). This method requires as many iterations as there are set bits, while the previous one has to shift up to the position of the highest bit. --- src/nxt_clang.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nxt_clang.h b/src/nxt_clang.h index 0622aad3..a9b8cd9e 100644 --- a/src/nxt_clang.h +++ b/src/nxt_clang.h @@ -143,8 +143,8 @@ nxt_popcount(unsigned int x) { int count; - for (count = 0; x != 0; x >>= 1) { - count += (x & 1); + for (count = 0; x != 0; count++) { + x &= x - 1; } return count;