Skip to content

Commit

Permalink
perf: 简单优化下pipeline读取逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Oct 9, 2023
1 parent 58b98f2 commit 8f0d2b3
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions source/MaaFramework/Resource/PipelineResMgr.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "PipelineResMgr.h"

#include "Utils/Logger.h"
#include "Utils/StringMisc.hpp"
#include "Vision/VisionTypes.h"

#include <tuple>
Expand Down Expand Up @@ -50,29 +51,30 @@ bool PipelineResMgr::load_all_json(const std::filesystem::path& path)
}

bool loaded = false;
if (std::filesystem::is_directory(path)) {
for (auto& entry : std::filesystem::recursive_directory_iterator(path)) {
if (!entry.is_regular_file() || entry.path().extension() != ".json") {
continue;
}
loaded = open_and_parse_file(entry.path());
if (!loaded) {
LogError << "open_and_parse_file failed" << VAR(entry.path());
return false;
}
}
if (!std::filesystem::is_directory(path)) {
LogError << "path is not directory" << VAR(path);
return false;
}
else if (std::filesystem::is_regular_file(path) && path.extension() == ".json") {
loaded = open_and_parse_file(path);

for (auto& entry : std::filesystem::recursive_directory_iterator(path)) {
auto& entry_path = entry.path();
if (!entry.is_regular_file()) {
LogWarn << "entry is not regular file, skip" << VAR(entry_path);
continue;
}
auto ext = path_to_utf8_string(entry_path.extension());
tolowers_(ext);
if (ext != ".json") {
LogWarn << "entry is not *.json, skip" << VAR(entry_path) << VAR(ext);
continue;
}

loaded &= open_and_parse_file(entry_path);
if (!loaded) {
LogError << "open_and_parse_file failed" << VAR(path);
LogError << "open_and_parse_file failed" << VAR(entry_path);
return false;
}
}
else {
LogError << "path is not directory or regular file";
return false;
}

return loaded;
}
Expand Down

0 comments on commit 8f0d2b3

Please sign in to comment.