From d044e79ebce7d7ad7e2e34ada1d9aff493e5f875 Mon Sep 17 00:00:00 2001 From: status102 <102887808+status102@users.noreply.github.com> Date: Sun, 27 Apr 2025 23:35:49 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20Task=E5=8A=A0=E8=BD=BD=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E5=89=8D=E9=87=8D=E5=A4=8D=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaCore/Config/TaskData.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/MaaCore/Config/TaskData.cpp b/src/MaaCore/Config/TaskData.cpp index c91b9ff9e1..b171cecded 100644 --- a/src/MaaCore/Config/TaskData.cpp +++ b/src/MaaCore/Config/TaskData.cpp @@ -222,7 +222,7 @@ bool asst::TaskData::load(const std::filesystem::path& path) { LogTraceScope("TaskData::load"); - json::value merged = json::object(); + json::object merged; if (is_regular_file(path)) { Log.debug("TaskData::load", "Loading json file:", path); @@ -231,7 +231,7 @@ bool asst::TaskData::load(const std::filesystem::path& path) Log.error("TaskData::load", "Json open failed:", path); return false; } - merged = ret.value(); + merged = ret->as_object(); } else if (is_directory(path)) { std::vector json_files; @@ -253,7 +253,10 @@ bool asst::TaskData::load(const std::filesystem::path& path) continue; } for (auto& [key, value] : file_json.as_object()) { - merged.as_object()[key] = std::move(value); + if (!merged.emplace(key, std::move(value)).second) { + Log.error(__FUNCTION__, "Duplicate key in json file:", file, key); + return false; + } } } }