Replace nlohmann/json with native C++20 JSON engine, cut build RAM/time, fix 32-bit build, enable -O2 -march=native
This commit is contained in:
@@ -324,6 +324,37 @@ int to_int_val(std::string_view s, int def) {
|
||||
return (int)v;
|
||||
}
|
||||
|
||||
bool read_file_str(std::string_view path, std::string &out) {
|
||||
out.clear();
|
||||
std::string p(path);
|
||||
FILE *f = std::fopen(p.c_str(), "rb");
|
||||
if (!f) return false;
|
||||
char buf[4096];
|
||||
size_t n;
|
||||
while ((n = std::fread(buf, 1, sizeof buf, f)) > 0) {
|
||||
out.append(buf, n);
|
||||
}
|
||||
bool ok = (std::ferror(f) == 0);
|
||||
std::fclose(f);
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool write_file_str(std::string_view path, std::string_view data) {
|
||||
std::string p(path);
|
||||
FILE *f = std::fopen(p.c_str(), "wb");
|
||||
if (!f) return false;
|
||||
size_t written = 0;
|
||||
while (written < data.size()) {
|
||||
size_t n = std::fwrite(data.data() + written, 1, data.size() - written, f);
|
||||
if (n == 0) {
|
||||
std::fclose(f);
|
||||
return false;
|
||||
}
|
||||
written += n;
|
||||
}
|
||||
return std::fclose(f) == 0;
|
||||
}
|
||||
|
||||
/* ----------------------------- signal --------------------------------- */
|
||||
static void sigint_handler(int sig) {
|
||||
(void)sig;
|
||||
|
||||
Reference in New Issue
Block a user