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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user