summaryrefslogtreecommitdiff
path: root/src/roadveh_cmd.cpp
diff options
context:
space:
mode:
authormaedhros <maedhros@openttd.org>2007-06-12 22:13:49 +0000
committermaedhros <maedhros@openttd.org>2007-06-12 22:13:49 +0000
commit12be876131ad76d0fb8e7d0fbff586ea1a0a693e (patch)
treef4b3d4a7be99176b7ebd3e1980b37402b5128f4c /src/roadveh_cmd.cpp
parentf3f744d36a60431a6845d2b7e3ce17e64ee2e4f5 (diff)
downloadopenttd-12be876131ad76d0fb8e7d0fbff586ea1a0a693e.tar.xz
(svn r10122) -Codechange: Add a CountBitsSet function and use it to replace some less efficient loops.
Diffstat (limited to 'src/roadveh_cmd.cpp')
-rw-r--r--src/roadveh_cmd.cpp9
1 files changed, 1 insertions, 8 deletions
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index b66483e70..5c5e4023b 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -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;