From 33d283fdb1710e40cff4daaabde6aa78325d4623 Mon Sep 17 00:00:00 2001 From: smatz Date: Sun, 18 Dec 2011 17:17:18 +0000 Subject: [PATCH] (svn r23588) -Codechange: use the 'final' keyword so compiler can optimise out some indirect calls --- src/aircraft.h | 2 +- src/blitter/32bpp_anim.hpp | 2 +- src/blitter/8bpp_optimized.hpp | 2 +- src/blitter/8bpp_simple.hpp | 2 +- src/effectvehicle_base.h | 2 +- src/roadveh.h | 2 +- src/ship.h | 2 +- src/station_base.h | 2 +- src/stdafx.h | 9 ++++++++- src/train.h | 2 +- src/vehicle_base.h | 2 +- src/waypoint_base.h | 2 +- 12 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/aircraft.h b/src/aircraft.h index 8ba313cfa2..938aaa4031 100644 --- a/src/aircraft.h +++ b/src/aircraft.h @@ -50,7 +50,7 @@ struct AircraftCache { /** * Aircraft, helicopters, rotors and their shadows belong to this class. */ -struct Aircraft : public SpecializedVehicle { +struct Aircraft FINAL : public SpecializedVehicle { uint16 crashed_counter; ///< Timer for handling crash animations. byte pos; ///< Next desired position of the aircraft. byte previous_pos; ///< Previous desired position of the aircraft. diff --git a/src/blitter/32bpp_anim.hpp b/src/blitter/32bpp_anim.hpp index 862a21c5d9..b1a5da5b40 100644 --- a/src/blitter/32bpp_anim.hpp +++ b/src/blitter/32bpp_anim.hpp @@ -15,7 +15,7 @@ #include "32bpp_optimized.hpp" /** The optimised 32 bpp blitter with palette animation. */ -class Blitter_32bppAnim : public Blitter_32bppOptimized { +class Blitter_32bppAnim FINAL : public Blitter_32bppOptimized { private: uint8 *anim_buf; ///< In this buffer we keep track of the 8bpp indexes so we can do palette animation int anim_buf_width; ///< The width of the animation buffer. diff --git a/src/blitter/8bpp_optimized.hpp b/src/blitter/8bpp_optimized.hpp index d6c5c89563..66fbe4091f 100644 --- a/src/blitter/8bpp_optimized.hpp +++ b/src/blitter/8bpp_optimized.hpp @@ -16,7 +16,7 @@ #include "factory.hpp" /** 8bpp blitter optimised for speed. */ -class Blitter_8bppOptimized : public Blitter_8bppBase { +class Blitter_8bppOptimized FINAL : public Blitter_8bppBase { public: /** Data stored about a (single) sprite. */ struct SpriteData { diff --git a/src/blitter/8bpp_simple.hpp b/src/blitter/8bpp_simple.hpp index b0af35e900..28102fcab0 100644 --- a/src/blitter/8bpp_simple.hpp +++ b/src/blitter/8bpp_simple.hpp @@ -16,7 +16,7 @@ #include "factory.hpp" /** Most trivial 8bpp blitter. */ -class Blitter_8bppSimple : public Blitter_8bppBase { +class Blitter_8bppSimple FINAL : public Blitter_8bppBase { public: /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom); /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator); diff --git a/src/effectvehicle_base.h b/src/effectvehicle_base.h index c16ee5f537..e3403b851d 100644 --- a/src/effectvehicle_base.h +++ b/src/effectvehicle_base.h @@ -22,7 +22,7 @@ * - bulldozer (road works) * - bubbles (industry) */ -struct EffectVehicle : public SpecializedVehicle { +struct EffectVehicle FINAL : public SpecializedVehicle { uint16 animation_state; ///< State primarily used to change the graphics/behaviour. byte animation_substate; ///< Sub state to time the change of the graphics/behaviour. diff --git a/src/roadveh.h b/src/roadveh.h index 3323ee9f5e..516c616fd2 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -84,7 +84,7 @@ void RoadVehUpdateCache(RoadVehicle *v, bool same_length = false); /** * Buses, trucks and trams belong to this class. */ -struct RoadVehicle : public GroundVehicle { +struct RoadVehicle FINAL : public GroundVehicle { byte state; ///< @see RoadVehicleStates byte frame; uint16 blocked_ctr; diff --git a/src/ship.h b/src/ship.h index d24d29db27..6096ae0554 100644 --- a/src/ship.h +++ b/src/ship.h @@ -21,7 +21,7 @@ WaterClass GetEffectiveWaterClass(TileIndex tile); /** * All ships have this type. */ -struct Ship: public SpecializedVehicle { +struct Ship FINAL : public SpecializedVehicle { TrackBitsByte state; ///< The "track" the ship is following. /** We don't want GCC to zero our struct! It already is zeroed and has an index! */ diff --git a/src/station_base.h b/src/station_base.h index 5ec337f563..a495f1691d 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -197,7 +197,7 @@ private: typedef SmallVector IndustryVector; /** Station data structure */ -struct Station : SpecializedStation { +struct Station FINAL : SpecializedStation { public: RoadStop *GetPrimaryRoadStop(RoadStopType type) const { diff --git a/src/stdafx.h b/src/stdafx.h index 7120ec1751..c75e4ca48d 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -128,6 +128,11 @@ /* Warn about functions using 'printf' format syntax. First argument determines which parameter * is the format string, second argument is start of values passed to printf. */ #define WARN_FORMAT(string, args) __attribute__ ((format (printf, string, args))) + #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) + #define FINAL final + #else + #define FINAL + #endif #endif /* __GNUC__ */ #if defined(__WATCOMC__) @@ -136,6 +141,7 @@ #define CDECL #define GCC_PACK #define WARN_FORMAT(string, args) + #define FINAL #include #endif /* __WATCOMC__ */ @@ -176,7 +182,6 @@ #pragma warning(disable: 6031) // code analyzer: Return value ignored: 'ReadFile' #pragma warning(disable: 6255) // code analyzer: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead #pragma warning(disable: 6246) // code analyzer: Local declaration of 'statspec' hides declaration of the same name in outer scope. For additional information, see previous declaration at ... - #define WARN_FORMAT(string, args) #include // alloca() #define NORETURN __declspec(noreturn) @@ -188,6 +193,8 @@ #endif #define GCC_PACK + #define WARN_FORMAT(string, args) + #define FINAL sealed int CDECL snprintf(char *str, size_t size, const char *format, ...) WARN_FORMAT(3, 4); #if defined(WINCE) diff --git a/src/train.h b/src/train.h index 9bc40fe975..37f64a2dce 100644 --- a/src/train.h +++ b/src/train.h @@ -67,7 +67,7 @@ struct TrainCache { /** * 'Train' is either a loco or a wagon. */ -struct Train : public GroundVehicle { +struct Train FINAL : public GroundVehicle { TrainCache tcache; /* Link between the two ends of a multiheaded engine */ diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 3a13ec4e72..7add6b6ff7 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -1009,7 +1009,7 @@ struct SpecializedVehicle : public Vehicle { /** * Disasters, like submarines, skyrangers and their shadows, belong to this class. */ -struct DisasterVehicle : public SpecializedVehicle { +struct DisasterVehicle FINAL : public SpecializedVehicle { SpriteID image_override; ///< Override for the default disaster vehicle sprite. VehicleID big_ufo_destroyer_target; ///< The big UFO that this destroyer is supposed to bomb. diff --git a/src/waypoint_base.h b/src/waypoint_base.h index 7265384d93..01c0ae173c 100644 --- a/src/waypoint_base.h +++ b/src/waypoint_base.h @@ -15,7 +15,7 @@ #include "base_station_base.h" /** Representation of a waypoint. */ -struct Waypoint : SpecializedStation { +struct Waypoint FINAL : SpecializedStation { uint16 town_cn; ///< The N-1th waypoint for this town (consecutive number) /**