diff options
-rw-r--r-- | src/core/bitmath_func.hpp | 12 | ||||
-rw-r--r-- | src/pathfinder/follow_track.hpp | 3 | ||||
-rw-r--r-- | src/pathfinder/npf/npf.cpp | 3 | ||||
-rw-r--r-- | src/station_gui.cpp | 2 | ||||
-rw-r--r-- | src/water_cmd.cpp | 6 |
5 files changed, 12 insertions, 14 deletions
diff --git a/src/core/bitmath_func.hpp b/src/core/bitmath_func.hpp index 85eaee6f9..a6b2ae446 100644 --- a/src/core/bitmath_func.hpp +++ b/src/core/bitmath_func.hpp @@ -310,16 +310,18 @@ static FORCEINLINE T ROR(const T x, const uint8 n) * Do an operation for each set set bit in a value. * * This macros is used to do an operation for each set - * bit in a variable. The first variable can be reused - * in the operation due to it's the bit position counter. - * The second variable will be cleared during the usage + * bit in a variable. The first parameter is a variable + * that is used as the bit position counter. + * The second parameter is an expression of the bits + * we need to iterate over. This expression will be + * evaluated once. * * @param i The position counter * @param b The value which we check for set bits */ #define FOR_EACH_SET_BIT(i, b) \ - for (i = 0; b != 0; i++, b >>= 1) \ - if (b & 1) + for (uint __FESB_bits = (i = 0, b); __FESB_bits != 0; i++, __FESB_bits >>= 1) \ + if (__FESB_bits & 1) #if defined(__APPLE__) diff --git a/src/pathfinder/follow_track.hpp b/src/pathfinder/follow_track.hpp index 6fdebc3e6..33e861c41 100644 --- a/src/pathfinder/follow_track.hpp +++ b/src/pathfinder/follow_track.hpp @@ -160,9 +160,8 @@ struct CFollowTrackT /* Mask already reserved trackdirs. */ m_new_td_bits &= ~TrackBitsToTrackdirBits(reserved); /* Mask out all trackdirs that conflict with the reservation. */ - uint bits = (uint)TrackdirBitsToTrackBits(m_new_td_bits); int i; - FOR_EACH_SET_BIT(i, bits) { + FOR_EACH_SET_BIT(i, TrackdirBitsToTrackBits(m_new_td_bits)) { if (TracksOverlap(reserved | TrackToTrackBits((Track)i))) m_new_td_bits &= ~TrackToTrackdirBits((Track)i); } if (m_new_td_bits == TRACKDIR_BIT_NONE) { diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp index b239d5c52..05ff2f4b0 100644 --- a/src/pathfinder/npf/npf.cpp +++ b/src/pathfinder/npf/npf.cpp @@ -921,9 +921,8 @@ static void NPFFollowTrack(AyStar *aystar, OpenListNode *current) TrackBits reserved = GetReservedTrackbits(dst_tile); trackdirbits &= ~TrackBitsToTrackdirBits(reserved); - uint bits = TrackdirBitsToTrackBits(trackdirbits); int i; - FOR_EACH_SET_BIT(i, bits) { + FOR_EACH_SET_BIT(i, TrackdirBitsToTrackBits(trackdirbits)) { if (TracksOverlap(reserved | TrackToTrackBits((Track)i))) trackdirbits &= ~TrackToTrackdirBits((Track)i); } } diff --git a/src/station_gui.cpp b/src/station_gui.cpp index bc0e6066b..8638acd07 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -567,7 +567,7 @@ public: FOR_EACH_SET_BIT(i, this->facilities) { this->RaiseWidget(i + SLW_TRAIN); } - SetBit(this->facilities, widget - SLW_TRAIN); + this->facilities = 1 << (widget - SLW_TRAIN); this->LowerWidget(widget); } this->stations.ForceRebuild(); diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index c3aadec8a..e93b268db 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -1008,9 +1008,8 @@ void TileLoop_Water(TileIndex tile) case FLOOD_DRYUP: { Slope slope_here = GetFoundationSlope(tile, NULL) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP; - uint check_dirs = _flood_from_dirs[slope_here]; uint dir; - FOR_EACH_SET_BIT(dir, check_dirs) { + FOR_EACH_SET_BIT(dir, _flood_from_dirs[slope_here]) { TileIndex dest = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir((Direction)dir)); if (dest == INVALID_TILE) continue; @@ -1048,9 +1047,8 @@ void ConvertGroundTilesIntoWaterTiles() break; default: - uint check_dirs = _flood_from_dirs[slope & ~SLOPE_STEEP]; uint dir; - FOR_EACH_SET_BIT(dir, check_dirs) { + FOR_EACH_SET_BIT(dir, _flood_from_dirs[slope & ~SLOPE_STEEP]) { TileIndex dest = TILE_ADD(tile, TileOffsByDir((Direction)dir)); Slope slope_dest = GetTileSlope(dest, NULL) & ~SLOPE_STEEP; if (slope_dest == SLOPE_FLAT || IsSlopeWithOneCornerRaised(slope_dest)) { |