diff options
author | Valentin Bartenev <vbart@nginx.com> | 2018-06-21 16:40:02 +0300 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2018-06-21 16:40:02 +0300 |
commit | af31012815e20f0c92ed6ea803638a16ba47b0c2 (patch) | |
tree | 7bf29d5e7a5be42b176a99cc8dc64273dd1cc669 /src | |
parent | 14bc4013941d38740d10681e7d54711f95cb38c4 (diff) | |
download | unit-af31012815e20f0c92ed6ea803638a16ba47b0c2.tar.gz unit-af31012815e20f0c92ed6ea803638a16ba47b0c2.tar.bz2 |
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.
Diffstat (limited to '')
-rw-r--r-- | src/nxt_clang.h | 4 |
1 files 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; |