| 412 | } |
| 413 | |
| 414 | DictPtr LoadOcdDictWithResourceProvider(const std::string& fileName) { |
| 415 | if (resourceProvider == nullptr) { |
| 416 | throw FileNotFound(fileName); |
| 417 | } |
| 418 | const std::shared_ptr<const ResourceProvider::Resource> resource = |
| 419 | resourceProvider->GetResource(fileName); |
| 420 | std::string cacheKey = "ocd\n" + resource->CacheKey(); |
| 421 | { |
| 422 | std::lock_guard<std::mutex> lock(DictCacheMutex()); |
| 423 | PruneExpiredDictCache(); |
| 424 | const auto cached = DictCache().find(cacheKey); |
| 425 | if (cached != DictCache().end()) { |
| 426 | DictPtr dict = cached->second.lock(); |
| 427 | if (dict != nullptr) { |
| 428 | return dict; |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | DictPtr dict = |
| 433 | DartsDict::NewFromBuffer(resource->Data(), resource->Size()); |
| 434 | { |
| 435 | std::lock_guard<std::mutex> lock(DictCacheMutex()); |
| 436 | PruneExpiredDictCache(); |
| 437 | std::weak_ptr<Dict>& cached = DictCache()[cacheKey]; |
| 438 | DictPtr cachedDict = cached.lock(); |
| 439 | if (cachedDict == nullptr) { |
| 440 | cached = dict; |
| 441 | return dict; |
| 442 | } |
| 443 | return cachedDict; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | DictPtr LoadOcd2DictWithResourceProvider(const std::string& fileName) { |
| 448 | if (resourceProvider == nullptr) { |
nothing calls this directly
no test coverage detected