| 445 | } |
| 446 | |
| 447 | DictPtr LoadOcd2DictWithResourceProvider(const std::string& fileName) { |
| 448 | if (resourceProvider == nullptr) { |
| 449 | throw FileNotFound(fileName); |
| 450 | } |
| 451 | |
| 452 | const std::shared_ptr<const ResourceProvider::Resource> resource = |
| 453 | resourceProvider->GetResource(fileName); |
| 454 | std::string cacheKey = "ocd2-marisa\n" + resource->CacheKey(); |
| 455 | { |
| 456 | std::lock_guard<std::mutex> lock(DictCacheMutex()); |
| 457 | PruneExpiredDictCache(); |
| 458 | const auto cached = DictCache().find(cacheKey); |
| 459 | if (cached != DictCache().end()) { |
| 460 | DictPtr dict = cached->second.lock(); |
| 461 | if (dict != nullptr) { |
| 462 | return dict; |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | DictPtr dict = MarisaDict::NewFromBuffer(resource->Data(), resource->Size()); |
| 468 | { |
| 469 | std::lock_guard<std::mutex> lock(DictCacheMutex()); |
| 470 | PruneExpiredDictCache(); |
| 471 | std::weak_ptr<Dict>& cached = DictCache()[cacheKey]; |
| 472 | DictPtr cachedDict = cached.lock(); |
| 473 | if (cachedDict == nullptr) { |
| 474 | cached = dict; |
| 475 | return dict; |
| 476 | } |
| 477 | return cachedDict; |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | DictPtr LoadDictFromFile(const std::string& type, |
| 482 | const std::string& fileName) { |
nothing calls this directly
no test coverage detected