mirror of
https://forge.fsky.io/oneflux/omegafox.git
synced 2026-04-11 09:02:03 -07:00
Improve GetJson perf
This commit is contained in:
parent
64180472e2
commit
da1fc5788c
1 changed files with 16 additions and 4 deletions
|
|
@ -45,6 +45,14 @@ inline std::optional<std::string> get_env_utf8(const std::string& name) {
|
||||||
|
|
||||||
inline const nlohmann::json& GetJson() {
|
inline const nlohmann::json& GetJson() {
|
||||||
static const nlohmann::json jsonConfig = []() {
|
static const nlohmann::json jsonConfig = []() {
|
||||||
|
static bool initialized = false;
|
||||||
|
static nlohmann::json config;
|
||||||
|
|
||||||
|
if (initialized) {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
std::string jsonString;
|
std::string jsonString;
|
||||||
int index = 1;
|
int index = 1;
|
||||||
|
|
||||||
|
|
@ -63,16 +71,20 @@ inline const nlohmann::json& GetJson() {
|
||||||
if (originalConfig) jsonString = *originalConfig;
|
if (originalConfig) jsonString = *originalConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jsonString.empty()) return nlohmann::json{};
|
if (jsonString.empty()) {
|
||||||
|
config = nlohmann::json{};
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
// Validate
|
// Validate
|
||||||
if (!nlohmann::json::accept(jsonString)) {
|
if (!nlohmann::json::accept(jsonString)) {
|
||||||
printf_stderr("ERROR: Invalid JSON passed to CAMOU_CONFIG!\n");
|
printf_stderr("ERROR: Invalid JSON passed to CAMOU_CONFIG!\n");
|
||||||
return nlohmann::json{};
|
config = nlohmann::json{};
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json result = nlohmann::json::parse(jsonString);
|
config = nlohmann::json::parse(jsonString);
|
||||||
return result;
|
return config;
|
||||||
}();
|
}();
|
||||||
return jsonConfig;
|
return jsonConfig;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue