Mercurial > fife-parpg
changeset 100:69a7d40ccf62
added hashing to pool to improve techdemo loading time
author | jasoka@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 22 Jul 2008 13:07:51 +0000 |
parents | 64e7fe3d4288 |
children | adf0f2b6d1b0 |
files | engine/core/util/resource/pool.cpp engine/core/util/resource/pool.h |
diffstat | 2 files changed, 9 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/engine/core/util/resource/pool.cpp Tue Jul 22 10:04:16 2008 +0000 +++ b/engine/core/util/resource/pool.cpp Tue Jul 22 13:07:51 2008 +0000 @@ -37,6 +37,7 @@ Pool::Pool(): m_entries(), + m_location_to_entry(), m_listeners(), m_loaders(), m_curind(0) @@ -61,6 +62,7 @@ delete (*entry); } m_entries.clear(); + m_location_to_entry.clear(); } void Pool::addResourceLoader(ResourceLoader* loader) { @@ -68,20 +70,16 @@ } int Pool::addResourceFromLocation(const ResourceLocation& loc) { - std::vector<PoolEntry*>::iterator it = m_entries.begin(); - int index = 0; - for (; it != m_entries.end(); it++) { - ResourceLocation* loc2 = (*it)->location; - if (*loc2 == loc) { - return index; - } - index++; + ResourceLocationToEntry::const_iterator it = m_location_to_entry.find(loc); + if (it != m_location_to_entry.end()) { + return (*it).second; } PoolEntry* entry = new PoolEntry(); entry->location = loc.clone(); m_entries.push_back(entry); - index = m_entries.size(); + size_t index = m_entries.size(); + m_location_to_entry[loc] = index; return index - 1; }
--- a/engine/core/util/resource/pool.h Tue Jul 22 10:04:16 2008 +0000 +++ b/engine/core/util/resource/pool.h Tue Jul 22 13:07:51 2008 +0000 @@ -151,6 +151,8 @@ void findAndSetProvider(PoolEntry& entry); std::vector<PoolEntry*> m_entries; + typedef std::map<ResourceLocation, int> ResourceLocationToEntry; + ResourceLocationToEntry m_location_to_entry; std::vector<IPoolListener*> m_listeners; std::vector<ResourceLoader*> m_loaders; int m_curind;