1
0
forked from 0ad/0ad

Improve component cache lookup performance slightly.

We do not need iteration order, and this makes this explicit.

Reviewed By: echotangoecho
Differential Revision: https://code.wildfiregames.com/D82
This was SVN commit r19235.
This commit is contained in:
leper 2017-02-22 19:27:58 +00:00
parent e1e4ef0370
commit 5e5b5be656
2 changed files with 5 additions and 4 deletions

View File

@ -525,7 +525,7 @@ void CComponentManager::ResetState()
m_ComponentsByTypeId.clear();
// Delete all SEntityComponentCaches
std::map<entity_id_t, SEntityComponentCache*>::iterator ccit = m_ComponentCaches.begin();
std::unordered_map<entity_id_t, SEntityComponentCache*>::iterator ccit = m_ComponentCaches.begin();
for (; ccit != m_ComponentCaches.end(); ++ccit)
free(ccit->second);
m_ComponentCaches.clear();
@ -829,7 +829,7 @@ CEntityHandle CComponentManager::AllocateEntityHandle(entity_id_t ent)
CEntityHandle CComponentManager::LookupEntityHandle(entity_id_t ent, bool allowCreate)
{
std::map<entity_id_t, SEntityComponentCache*>::iterator it;
std::unordered_map<entity_id_t, SEntityComponentCache*>::iterator it;
it = m_ComponentCaches.find(ent);
if (it == m_ComponentCaches.end())
{

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2016 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -29,6 +29,7 @@
#include <boost/unordered_map.hpp>
#include <map>
#include <unordered_map>
class IComponent;
class CParamNode;
@ -372,7 +373,7 @@ private:
std::map<MessageTypeId, CDynamicSubscription> m_DynamicMessageSubscriptionsNonsync;
std::map<IComponent*, std::set<MessageTypeId> > m_DynamicMessageSubscriptionsNonsyncByComponent;
std::map<entity_id_t, SEntityComponentCache*> m_ComponentCaches;
std::unordered_map<entity_id_t, SEntityComponentCache*> m_ComponentCaches;
// TODO: maintaining both ComponentsBy* is nasty; can we get rid of one,
// while keeping QueryInterface and PostMessage sufficiently efficient?