| 376 | } |
| 377 | |
| 378 | DictPtr LoadTextDartsDictWithResourceProvider(const std::string& fileName) { |
| 379 | if (resourceProvider == nullptr) { |
| 380 | throw FileNotFound(fileName); |
| 381 | } |
| 382 | |
| 383 | const std::shared_ptr<const ResourceProvider::Resource> resource = |
| 384 | resourceProvider->GetResource(fileName); |
| 385 | std::string cacheKey = "text-darts\n" + resource->CacheKey(); |
| 386 | { |
| 387 | std::lock_guard<std::mutex> lock(DictCacheMutex()); |
| 388 | PruneExpiredDictCache(); |
| 389 | const auto cached = DictCache().find(cacheKey); |
| 390 | if (cached != DictCache().end()) { |
| 391 | DictPtr dict = cached->second.lock(); |
| 392 | if (dict != nullptr) { |
| 393 | return dict; |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | TextDictPtr textDict = TextDict::NewFromBuffer(resource->Data(), |
| 399 | resource->Size()); |
| 400 | DictPtr dict = DartsDict::NewFromDict(*textDict.get()); |
| 401 | { |
| 402 | std::lock_guard<std::mutex> lock(DictCacheMutex()); |
| 403 | PruneExpiredDictCache(); |
| 404 | std::weak_ptr<Dict>& cached = DictCache()[cacheKey]; |
| 405 | DictPtr cachedDict = cached.lock(); |
| 406 | if (cachedDict == nullptr) { |
| 407 | cached = dict; |
| 408 | return dict; |
| 409 | } |
| 410 | return cachedDict; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | DictPtr LoadOcdDictWithResourceProvider(const std::string& fileName) { |
| 415 | if (resourceProvider == nullptr) { |
nothing calls this directly
no test coverage detected