Mercurial > fife-parpg
diff engine/core/util/resource/pool.cpp @ 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 | 90005975cdbb |
children | d2f1e81fbe2c |
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; }