MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / LoadOcdDictWithResourceProvider

Method LoadOcdDictWithResourceProvider

src/Config.cpp:414–445  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 5

PruneExpiredDictCacheFunction · 0.85
GetResourceMethod · 0.80
findMethod · 0.80
endMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected