From 5cf68416d8b86bb9c8bfa31909f3ce584ce58c09 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Wed, 19 Aug 2020 15:34:04 -0700 Subject: [PATCH] Don't bother comparing field names in parserandom --- benchmark/bench_sax.cpp | 8 ++++---- src/generic/ondemand/object-inl.h | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/benchmark/bench_sax.cpp b/benchmark/bench_sax.cpp index 874a55fe2..6ee3d2f8b 100644 --- a/benchmark/bench_sax.cpp +++ b/benchmark/bench_sax.cpp @@ -269,8 +269,8 @@ static void dom_parse_largerandom(State &state) { std::cerr << "failure: " << error << std::endl; throw "Parsing failed"; }; - for (auto p : doc) { - container.emplace_back(my_point{p["x"], p["y"], p["z"]}); + for (auto point : doc) { + container.emplace_back(my_point{point["x"], point["y"], point["z"]}); } bytes += json.size(); benchmark::DoNotOptimize(container.data()); @@ -308,8 +308,8 @@ static void ondemand_parse_largerandom(State &state) { size_t bytes = 0; for (SIMDJSON_UNUSED auto _ : state) { std::vector container; - for (ondemand::object p : parser.parse(json)) { - container.emplace_back(my_point{p["x"], p["y"], p["z"]}); + for (ondemand::object point : parser.parse(json)) { + container.emplace_back(my_point{(*point).value(), (*++point).value(), (*++point).value()}); } bytes += json.size(); benchmark::DoNotOptimize(container.data()); diff --git a/src/generic/ondemand/object-inl.h b/src/generic/ondemand/object-inl.h index 9f3dcbec7..3ad24ca06 100644 --- a/src/generic/ondemand/object-inl.h +++ b/src/generic/ondemand/object-inl.h @@ -133,6 +133,12 @@ simdjson_really_inline object object::end() noexcept { } simdjson_really_inline simdjson_result object::operator*() noexcept { + // For people who use the iterator raw + if (at_start) { first_field(); } + if (finished()) { + logger::log_error(doc->iter, "Attempt to get field from empty object"); + return { doc, NO_SUCH_FIELD }; + } if (error) { finish(); return { doc, error }; } return field::start(doc); }