From 5f084cd98d7b3326b51320455364337539710efd Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Wed, 5 Oct 2016 00:13:10 +0200 Subject: Make some maps unordered to improve performance * This permit to improve performance on C++11 builds * use some existing typedefs in tools maps * minor code style changes --- src/tool.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src/tool.cpp') diff --git a/src/tool.cpp b/src/tool.cpp index 54b9f15f4..20b71fb31 100644 --- a/src/tool.cpp +++ b/src/tool.cpp @@ -34,24 +34,23 @@ void ToolCapabilities::serialize(std::ostream &os, u16 protocol_version) const writeF1000(os, full_punch_interval); writeS16(os, max_drop_level); writeU32(os, groupcaps.size()); - for(std::map::const_iterator - i = groupcaps.begin(); i != groupcaps.end(); ++i){ + for (ToolGCMap::const_iterator i = groupcaps.begin(); i != groupcaps.end(); ++i) { const std::string *name = &i->first; const ToolGroupCap *cap = &i->second; os<uses); writeS16(os, cap->maxlevel); writeU32(os, cap->times.size()); - for(std::map::const_iterator - i = cap->times.begin(); i != cap->times.end(); ++i){ + for (UNORDERED_MAP::const_iterator + i = cap->times.begin(); i != cap->times.end(); ++i) { writeS16(os, i->first); writeF1000(os, i->second); } } if(protocol_version > 17){ writeU32(os, damageGroups.size()); - for(std::map::const_iterator - i = damageGroups.begin(); i != damageGroups.end(); ++i){ + for (DamageGroup::const_iterator i = damageGroups.begin(); + i != damageGroups.end(); ++i) { os<first); writeS16(os, i->second); } @@ -106,7 +105,7 @@ DigParams getDigParams(const ItemGroupList &groups, default: break; } - + // Values to be returned (with a bit of conversion) bool result_diggable = false; float result_time = 0.0; @@ -115,8 +114,8 @@ DigParams getDigParams(const ItemGroupList &groups, int level = itemgroup_get(groups, "level"); //infostream<<"level="<::const_iterator - i = tp->groupcaps.begin(); i != tp->groupcaps.end(); ++i){ + for (ToolGCMap::const_iterator i = tp->groupcaps.begin(); + i != tp->groupcaps.end(); ++i) { const std::string &name = i->first; //infostream<<"group="<second; @@ -163,8 +162,8 @@ HitParams getHitParams(const ItemGroupList &armor_groups, s16 damage = 0; float full_punch_interval = tp->full_punch_interval; - for(std::map::const_iterator - i = tp->damageGroups.begin(); i != tp->damageGroups.end(); ++i){ + for (DamageGroup::const_iterator i = tp->damageGroups.begin(); + i != tp->damageGroups.end(); ++i) { s16 armor = itemgroup_get(armor_groups, i->first); damage += i->second * rangelim(time_from_last_punch / full_punch_interval, 0.0, 1.0) * armor / 100.0; @@ -197,7 +196,7 @@ PunchDamageResult getPunchDamage( do_hit = false; } } - + PunchDamageResult result; if(do_hit) { -- cgit v1.2.3