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

Method LoadTextDartsDictWithResourceProvider

src/Config.cpp:378–412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected