use SetDataTable files as map indexes

This commit is contained in:
Martin Michelsen
2024-01-20 15:30:24 -08:00
parent fe1d5a874a
commit e13b5950ca
82 changed files with 689 additions and 159 deletions
+1 -8
View File
@@ -79,20 +79,13 @@ shared_ptr<const string> ThreadSafeFileCache::get(
const string& name, std::function<shared_ptr<const string>(const std::string&)> generate) {
try {
shared_lock g(this->lock);
auto ret = this->name_to_file.at(name);
if (!ret) {
throw cannot_open_file(name);
}
return ret;
return this->name_to_file.at(name);
} catch (const out_of_range&) {
unique_lock g(this->lock);
auto it = this->name_to_file.find(name);
if (it == this->name_to_file.end()) {
it = this->name_to_file.emplace(name, generate(name)).first;
}
if (!it->second) {
throw cannot_open_file(name);
}
return it->second;
}
}