changeset 18740:3dcacc91f96f draft

(svn r23588) -Codechange: use the 'final' keyword so compiler can optimise out some indirect calls
author smatz <smatz@openttd.org>
date Sun, 18 Dec 2011 17:17:18 +0000
parents 35dbea1cf5d2
children 0f8563e31943
files src/aircraft.h src/blitter/32bpp_anim.hpp src/blitter/8bpp_optimized.hpp src/blitter/8bpp_simple.hpp src/effectvehicle_base.h src/roadveh.h src/ship.h src/station_base.h src/stdafx.h src/train.h src/vehicle_base.h src/waypoint_base.h
diffstat 12 files changed, 19 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/aircraft.h
+++ b/src/aircraft.h
@@ -50,7 +50,7 @@
 /**
  * Aircraft, helicopters, rotors and their shadows belong to this class.
  */
-struct Aircraft : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
+struct Aircraft FINAL : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
 	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.
--- 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.
--- 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 {
--- 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);
--- a/src/effectvehicle_base.h
+++ b/src/effectvehicle_base.h
@@ -22,7 +22,7 @@
  *  - bulldozer (road works)
  *  - bubbles (industry)
  */
-struct EffectVehicle : public SpecializedVehicle<EffectVehicle, VEH_EFFECT> {
+struct EffectVehicle FINAL : public SpecializedVehicle<EffectVehicle, VEH_EFFECT> {
 	uint16 animation_state;  ///< State primarily used to change the graphics/behaviour.
 	byte animation_substate; ///< Sub state to time the change of the graphics/behaviour.
 
--- a/src/roadveh.h
+++ b/src/roadveh.h
@@ -84,7 +84,7 @@
 /**
  * Buses, trucks and trams belong to this class.
  */
-struct RoadVehicle : public GroundVehicle<RoadVehicle, VEH_ROAD> {
+struct RoadVehicle FINAL : public GroundVehicle<RoadVehicle, VEH_ROAD> {
 	byte state;             ///< @see RoadVehicleStates
 	byte frame;
 	uint16 blocked_ctr;
--- a/src/ship.h
+++ b/src/ship.h
@@ -21,7 +21,7 @@
 /**
  * All ships have this type.
  */
-struct Ship: public SpecializedVehicle<Ship, VEH_SHIP> {
+struct Ship FINAL : public SpecializedVehicle<Ship, VEH_SHIP> {
 	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! */
--- a/src/station_base.h
+++ b/src/station_base.h
@@ -197,7 +197,7 @@
 typedef SmallVector<Industry *, 2> IndustryVector;
 
 /** Station data structure */
-struct Station : SpecializedStation<Station, false> {
+struct Station FINAL : SpecializedStation<Station, false> {
 public:
 	RoadStop *GetPrimaryRoadStop(RoadStopType type) const
 	{
--- 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 <malloc.h>
 #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 <malloc.h> // 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)
--- a/src/train.h
+++ b/src/train.h
@@ -67,7 +67,7 @@
 /**
  * 'Train' is either a loco or a wagon.
  */
-struct Train : public GroundVehicle<Train, VEH_TRAIN> {
+struct Train FINAL : public GroundVehicle<Train, VEH_TRAIN> {
 	TrainCache tcache;
 
 	/* Link between the two ends of a multiheaded engine */
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -1009,7 +1009,7 @@
 /**
  * Disasters, like submarines, skyrangers and their shadows, belong to this class.
  */
-struct DisasterVehicle : public SpecializedVehicle<DisasterVehicle, VEH_DISASTER> {
+struct DisasterVehicle FINAL : public SpecializedVehicle<DisasterVehicle, VEH_DISASTER> {
 	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.
 
--- 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<Waypoint, true> {
+struct Waypoint FINAL : SpecializedStation<Waypoint, true> {
 	uint16 town_cn;    ///< The N-1th waypoint for this town (consecutive number)
 
 	/**