MCPcopy Create free account
hub / github.com/Tencent/libpag / FindFileByPath

Function FindFileByPath

src/base/File.cpp:29–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27 std::unordered_map<std::string, std::weak_ptr<File>>();
28
29static std::shared_ptr<File> FindFileByPath(const std::string& filePath) {
30 std::lock_guard<std::mutex> autoLock(globalLocker);
31 if (filePath.empty()) {
32 return nullptr;
33 }
34 auto result = weakFileMap.find(filePath);
35 if (result != weakFileMap.end()) {
36 auto& weak = result->second;
37 auto file = weak.lock();
38 if (file) {
39 return file;
40 }
41 weakFileMap.erase(result);
42 if (weakFileMap.size() > 50) { // do cleaning.
43 std::vector<std::string> needRemoveList = {};
44 for (auto& item : weakFileMap) {
45 if (item.second.expired()) {
46 needRemoveList.push_back(item.first);
47 }
48 }
49 for (auto& item : needRemoveList) {
50 weakFileMap.erase(item);
51 }
52 }
53 }
54 return nullptr;
55}
56
57std::shared_ptr<File> File::Load(const std::string& filePath) {
58 auto byteData = ByteData::FromPath(filePath);

Callers 1

LoadMethod · 0.85

Calls 4

emptyMethod · 0.80
findMethod · 0.80
sizeMethod · 0.80
push_backMethod · 0.80

Tested by

no test coverage detected