8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 99128d9 commit 93a368dCopy full SHA for 93a368d
src/node_snapshotable.cc
@@ -11,7 +11,6 @@
11
#include "embedded_data.h"
12
#include "encoding_binding.h"
13
#include "env-inl.h"
14
-#include "json_parser.h"
15
#include "node_blob.h"
16
#include "node_builtins.h"
17
#include "node_contextify.h"
@@ -27,6 +26,7 @@
27
26
#include "node_url.h"
28
#include "node_v8.h"
29
#include "node_v8_platform-inl.h"
+#include "simdjson.h"
30
#include "timers.h"
31
32
#if HAVE_INSPECTOR
@@ -909,32 +909,61 @@ std::optional<SnapshotConfig> ReadSnapshotConfig(const char* config_path) {
909
return std::nullopt;
910
}
911
912
- JSONParser parser;
913
- if (!parser.Parse(config_content)) {
914
- FPrintF(stderr, "Cannot parse JSON from %s\n", config_path);
915
- return std::nullopt;
916
- }
917
-
918
SnapshotConfig result;
919
- result.builder_script_path = parser.GetTopLevelStringField("builder");
920
- if (!result.builder_script_path.has_value()) {
+
+ simdjson::ondemand::parser parser;
+ simdjson::ondemand::document document;
+ simdjson::ondemand::object main_object;
+ simdjson::error_code error =
+ parser.iterate(simdjson::pad(config_content)).get(document);
+ if (!error) {
921
+ error = document.get_object().get(main_object);
922
+ }
923
+ if (error) {
924
FPrintF(stderr,
- "\"builder\" field of %s is not a non-empty string\n",
- config_path);
925
+ "Cannot parse JSON from %s: %s\n",
926
+ config_path,
927
+ simdjson::error_message(error));
928
929
930
- std::optional<bool> WithoutCodeCache =
- parser.GetTopLevelBoolField("withoutCodeCache");
- if (!WithoutCodeCache.has_value()) {
931
+ for (auto field : main_object) {
932
+ std::string_view key;
933
+ if (field.unescaped_key().get(key)) {
934
+ FPrintF(stderr, "Cannot read key from %s\n", config_path);
935
+ return std::nullopt;
936
937
+ if (key == "builder") {
938
+ std::string builder_path;
939
+ if (field.value().get_string().get(builder_path) ||
940
+ builder_path.empty()) {
941
+ FPrintF(stderr,
942
+ "\"builder\" field of %s is not a non-empty string\n",
943
+ config_path);
944
945
946
+ result.builder_script_path = builder_path;
947
+ } else if (key == "withoutCodeCache") {
948
+ bool without_code_cache_value = false;
949
+ if (field.value().get_bool().get(without_code_cache_value)) {
950
951
+ "\"withoutCodeCache\" field of %s is not a boolean\n",
952
953
954
955
+ if (without_code_cache_value) {
956
+ result.flags |= SnapshotFlags::kWithoutCodeCache;
957
958
959
960
961
+ if (!result.builder_script_path.has_value()) {
962
- "\"withoutCodeCache\" field of %s is not a boolean\n",
963
964
config_path);
965
966
- if (WithoutCodeCache.value()) {
- result.flags |= SnapshotFlags::kWithoutCodeCache;
967
968
return result;
969