🔥 use simdjson instead of nlohmannjson

This commit is contained in:
Vladislav Nepogodin 2021-12-31 18:24:03 +04:00
parent 119d4a5767
commit 5f95fbab5c
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
5 changed files with 41 additions and 3 deletions

View File

@ -105,21 +105,21 @@ add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language :
executable(
'cachyos-installer',
src_files,
dependencies: [fmt, spdlog, ftxui, cpr, glibmm],
dependencies: [fmt, spdlog, ftxui, simdjson, cpr, glibmm],
include_directories: [include_directories('src')],
install: true)
executable(
'test-exec-interactive',
files('src/config.cpp', 'src/tui.cpp', 'src/utils.cpp', 'src/main_test.cpp'),
dependencies: [fmt, spdlog, ftxui, cpr, glibmm],
dependencies: [fmt, spdlog, ftxui, simdjson, cpr, glibmm],
include_directories: [include_directories('src')],
install: false)
executable(
'test-process-tailing',
files('src/config.cpp', 'src/widgets.cpp', 'src/tui.cpp', 'src/utils.cpp', 'src/follow_process_log.cpp','src/test_proccess_tailing.cpp'),
dependencies: [fmt, spdlog, ftxui, cpr, glibmm],
dependencies: [fmt, spdlog, ftxui, simdjson, cpr, glibmm],
include_directories: [include_directories('src')],
install: false)

View File

@ -25,6 +25,8 @@ int main() {
return 1;
}
utils::parse_config();
if (!Config::initialize()) {
return 1;
}

View File

@ -46,6 +46,23 @@ namespace ranges = std::ranges;
#include <cpr/timeout.h>
#endif
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-conversion"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wuseless-cast"
#endif
#include <simdjson.h>
#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
namespace fs = std::filesystem;
namespace utils {
@ -465,4 +482,18 @@ void show_iwctl() noexcept {
}
}
void parse_config() noexcept {
using namespace simdjson;
ondemand::parser parser;
padded_string json = padded_string::load("test.json");
ondemand::document doc = parser.iterate(json);
for (auto entry : doc["steps"]) {
std::string_view step;
entry.get(step);
std::cout << step << '\n';
}
}
} // namespace utils

View File

@ -34,6 +34,8 @@ void id_system() noexcept;
[[nodiscard]] bool handle_connection() noexcept;
void show_iwctl() noexcept;
void parse_config() noexcept;
template <typename T = std::int32_t,
typename = std::enable_if_t<std::numeric_limits<T>::is_integer>>
inline T to_int(const std::string_view& str) {

3
test.json Normal file
View File

@ -0,0 +1,3 @@
{
"steps": ["locale", "partitions_encryption", "keyboard", "users", "summary", "netinstall", "finish"]
}