comparison 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
comparison
equal deleted inserted replaced
99:64e7fe3d4288 100:69a7d40ccf62
35 namespace FIFE { 35 namespace FIFE {
36 static Logger _log(LM_POOL); 36 static Logger _log(LM_POOL);
37 37
38 Pool::Pool(): 38 Pool::Pool():
39 m_entries(), 39 m_entries(),
40 m_location_to_entry(),
40 m_listeners(), 41 m_listeners(),
41 m_loaders(), 42 m_loaders(),
42 m_curind(0) 43 m_curind(0)
43 { 44 {
44 } 45 }
59 std::vector<PoolEntry*>::iterator entry; 60 std::vector<PoolEntry*>::iterator entry;
60 for (entry = m_entries.begin(); entry != m_entries.end(); entry++) { 61 for (entry = m_entries.begin(); entry != m_entries.end(); entry++) {
61 delete (*entry); 62 delete (*entry);
62 } 63 }
63 m_entries.clear(); 64 m_entries.clear();
65 m_location_to_entry.clear();
64 } 66 }
65 67
66 void Pool::addResourceLoader(ResourceLoader* loader) { 68 void Pool::addResourceLoader(ResourceLoader* loader) {
67 m_loaders.push_back(loader); 69 m_loaders.push_back(loader);
68 } 70 }
69 71
70 int Pool::addResourceFromLocation(const ResourceLocation& loc) { 72 int Pool::addResourceFromLocation(const ResourceLocation& loc) {
71 std::vector<PoolEntry*>::iterator it = m_entries.begin(); 73 ResourceLocationToEntry::const_iterator it = m_location_to_entry.find(loc);
72 int index = 0; 74 if (it != m_location_to_entry.end()) {
73 for (; it != m_entries.end(); it++) { 75 return (*it).second;
74 ResourceLocation* loc2 = (*it)->location;
75 if (*loc2 == loc) {
76 return index;
77 }
78 index++;
79 } 76 }
80 77
81 PoolEntry* entry = new PoolEntry(); 78 PoolEntry* entry = new PoolEntry();
82 entry->location = loc.clone(); 79 entry->location = loc.clone();
83 m_entries.push_back(entry); 80 m_entries.push_back(entry);
84 index = m_entries.size(); 81 size_t index = m_entries.size();
82 m_location_to_entry[loc] = index;
85 return index - 1; 83 return index - 1;
86 } 84 }
87 85
88 int Pool::addResourceFromFile(const std::string& filename) { 86 int Pool::addResourceFromFile(const std::string& filename) {
89 return addResourceFromLocation(ResourceLocation(filename)); 87 return addResourceFromLocation(ResourceLocation(filename));