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

Method LoadOcd2DictWithResourceProvider

src/Config.cpp:447–479  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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