| 153 | } |
| 154 | |
| 155 | bool CaseCache::store(LPCWSTR dirpath, const list<wstring>& files) |
| 156 | { |
| 157 | bool bRet = true; |
| 158 | |
| 159 | wstring key; |
| 160 | |
| 161 | if (!touppercase(dirpath, key)) |
| 162 | return false; |
| 163 | |
| 164 | lock(); |
| 165 | |
| 166 | try { |
| 167 | // see if it's already there |
| 168 | auto mp = m_map.emplace(key, (CaseCacheNode*)NULL); |
| 169 | |
| 170 | if (mp.second) { |
| 171 | |
| 172 | CaseCacheNode *node = NULL; |
| 173 | |
| 174 | // if it isn't, then see if the cache is full |
| 175 | |
| 176 | // if so, remove oldest entry (from tail of linked list) |
| 177 | |
| 178 | if (m_map.size() > CASE_CACHE_ENTRIES) { |
| 179 | node = m_lru_list.back(); |
| 180 | m_lru_list.pop_back(); |
| 181 | m_map.erase(node->m_key); |
| 182 | node->m_files.clear(); |
| 183 | } |
| 184 | |
| 185 | // re-use node if we removed one, otherwise get one from spare list, otherwise make a new one |
| 186 | |
| 187 | if (!node) { |
| 188 | if (!m_spare_node_list.empty()) { |
| 189 | node = m_spare_node_list.front(); |
| 190 | m_spare_node_list.pop_front(); |
| 191 | } else { |
| 192 | node = new CaseCacheNode; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | mp.first->second = node; |
| 197 | |
| 198 | node->m_key = mp.first->first; |
| 199 | node->m_path = dirpath; |
| 200 | wstring ucfile; |
| 201 | for (auto it = files.begin(); it != files.end(); ++it) { |
| 202 | if (!touppercase(it->c_str(), ucfile)) { |
| 203 | throw(-1); |
| 204 | } |
| 205 | node->m_files.insert(make_pair(ucfile, *it)); |
| 206 | } |
| 207 | node->m_timestamp = GetTickCount64(); |
| 208 | GetSystemTimeAsFileTime(&node->m_filetime); |
| 209 | m_lru_list.push_front(node); |
| 210 | node->m_list_it = m_lru_list.begin(); |
| 211 | |
| 212 | } else { |
no test coverage detected