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.
This commit is contained in:
Valentin Bartenev
2018-06-21 16:40:02 +03:00
parent 14bc401394
commit af31012815

View File

@@ -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;