(svn r10122) -Codechange: Add a CountBitsSet function and use it to replace some less efficient loops.

This commit is contained in:
maedhros
2007-06-12 22:13:49 +00:00
parent f3f744d36a
commit 12be876131
4 changed files with 22 additions and 20 deletions

View File

@@ -1085,15 +1085,8 @@ static void RoadZPosAffectSpeed(Vehicle *v, byte old_z)
static int PickRandomBit(uint bits)
{
uint num = 0;
uint b = bits;
uint i;
do {
if (b & 1) num++;
} while (b >>= 1);
num = RandomRange(num);
uint num = RandomRange(CountBitsSet(bits));
for (i = 0; !(bits & 1) || (int)--num >= 0; bits >>= 1, i++) {}
return i;