From 54f4b77966e9cfd34b4b4d22f6f26a8472196b61 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Thu, 19 Jun 2014 13:18:33 -0400 Subject: [PATCH] inline functions using expensive boost includes in map_location From running scons with compiler flag -H it seems like these actually include quite a bit, and most of it does not have include guards. --- src/map_location.cpp | 23 +++++++++++++++++++++++ src/map_location.hpp | 21 ++++----------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/map_location.cpp b/src/map_location.cpp index 7e753eab499..d16f8bf723d 100644 --- a/src/map_location.cpp +++ b/src/map_location.cpp @@ -28,6 +28,9 @@ #include "gettext.hpp" #include "util.hpp" +#include +#include + #define ERR_CF LOG_STREAM(err, config) #define LOG_G LOG_STREAM(info, general) #define DBG_G LOG_STREAM(debug, general) @@ -44,6 +47,26 @@ std::ostream &operator<<(std::ostream &s, std::vector const &v) { return s; } +/** + * Default list of directions + * + * Moved out of inline, because boost assign list_of is somewhat expensive... + * + **/ +const std::vector & map_location::default_dirs() { + static const std::vector dirs = boost::assign::list_of(map_location::NORTH) + (map_location::NORTH_EAST)(map_location::SOUTH_EAST)(map_location::SOUTH) + (map_location::SOUTH_WEST)(map_location::NORTH_WEST); + return dirs; +} + +/** Moved out of inline because of the boost dependency **/ +std::size_t hash_value(map_location const & a){ + boost::hash h; + return h( (a.x << 16) ^ a.y ); +} + + map_location::DIRECTION map_location::parse_direction(const std::string& str) { if(!str.empty()) { diff --git a/src/map_location.hpp b/src/map_location.hpp index 2eb407738b9..c3429d211a1 100644 --- a/src/map_location.hpp +++ b/src/map_location.hpp @@ -20,11 +20,10 @@ class config; class variable_set; +#include +#include #include #include -#include -#include -#include /** * Encapsulates the map of the game. @@ -146,18 +145,6 @@ std::ostream &operator<<(std::ostream &s, map_location const &l); std::ostream &operator<<(std::ostream &s, std::vector const &v); /** Inlined bodies **/ -inline std::size_t hash_value(map_location const & a){ - boost::hash h; - return h( (a.x << 16) ^ a.y ); -} - -/** Inline list of directions **/ -inline const std::vector & map_location::default_dirs() { - static const std::vector dirs = boost::assign::list_of(map_location::NORTH) - (map_location::NORTH_EAST)(map_location::SOUTH_EAST)(map_location::SOUTH) - (map_location::SOUTH_WEST)(map_location::NORTH_WEST); - return dirs; -} /** Inline direction manipulators **/ inline map_location::DIRECTION map_location::rotate_right(map_location::DIRECTION d, unsigned int k) { @@ -364,7 +351,7 @@ inline bool tiles_adjacent(const map_location& a, const map_location& b) inline size_t distance_between(const map_location& a, const map_location& b) { - const size_t hdistance = abs(a.x - b.x); + const size_t hdistance = std::abs(a.x - b.x); const size_t vpenalty = ( (((a.x & 1)==0) && ((b.x & 1)==1) && (a.y < b.y)) || (((b.x & 1)==0) && ((a.x & 1)==1) && (b.y < a.y)) ) ? 1 : 0; @@ -379,7 +366,7 @@ inline size_t distance_between(const map_location& a, const map_location& b) // = maximum(hdistance, vdistance+hdistance-hdistance/2-hdistance%2) // = maximum(hdistance,abs(a.y-b.y)+vpenalty+hdistance/2) - return std::max(hdistance, abs(a.y - b.y) + vpenalty + hdistance/2); + return std::max(hdistance, std::abs(a.y - b.y) + vpenalty + hdistance/2); }