diff options
author | maedhros <maedhros@openttd.org> | 2007-06-12 22:13:49 +0000 |
---|---|---|
committer | maedhros <maedhros@openttd.org> | 2007-06-12 22:13:49 +0000 |
commit | 12be876131ad76d0fb8e7d0fbff586ea1a0a693e (patch) | |
tree | f4b3d4a7be99176b7ebd3e1980b37402b5128f4c /src/economy.cpp | |
parent | f3f744d36a60431a6845d2b7e3ce17e64ee2e4f5 (diff) | |
download | openttd-12be876131ad76d0fb8e7d0fbff586ea1a0a693e.tar.xz |
(svn r10122) -Codechange: Add a CountBitsSet function and use it to replace some less efficient loops.
Diffstat (limited to 'src/economy.cpp')
-rw-r--r-- | src/economy.cpp | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/src/economy.cpp b/src/economy.cpp index 64bcbe832..967373c73 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -67,10 +67,7 @@ int64 CalculateCompanyValue(const Player* p) uint num = 0; FOR_ALL_STATIONS(st) { - if (st->owner == owner) { - uint facil = st->facilities; - do num += (facil&1); while (facil >>= 1); - } + if (st->owner == owner) num += CountBitsSet(st->facilities); } value = num * _price.station_value * 25; @@ -144,10 +141,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update) const Station* st; FOR_ALL_STATIONS(st) { - if (st->owner == owner) { - int facil = st->facilities; - do num += facil&1; while (facil>>=1); - } + if (st->owner == owner) num += CountBitsSet(st->facilities); } _score_part[owner][SCORE_STATIONS] = num; } @@ -196,9 +190,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update) /* Generate score for variety of cargo */ { - uint cargo = p->cargo_types; - uint num = 0; - do num += cargo&1; while (cargo>>=1); + uint num = CountBitsSet(p->cargo_types); _score_part[owner][SCORE_CARGO] = num; if (update) p->cargo_types = 0; } |