work on the ondemand iterators (#2590)

* work on the ondemand iterators

* guarding two SIMDJSON_ASSUME

* simplify following @jkeiser's comment

* adding safety rails to the iterators

* silencing a warning.

* updating the amalgamation files
This commit is contained in:
Daniel Lemire
2026-01-17 21:15:18 -05:00
committed by GitHub
parent 2c7fbc1538
commit feb1e7feb6
18 changed files with 27686 additions and 21054 deletions
+18 -1
View File
@@ -6,7 +6,23 @@ using namespace simdjson;
namespace array_tests {
using namespace std;
using simdjson::ondemand::json_type;
bool std_advance() {
TEST_START();
auto json = R"( [ {"key" : "value1"}, {"key" : "value2"} ] )"_padded;
ondemand::parser parser;
ondemand::document doc;
ASSERT_SUCCESS(parser.iterate(json).get(doc));
ondemand::array arr;
ASSERT_SUCCESS(doc.get_array().get(arr));
auto iter = arr.begin();
std::advance(iter, 1);
ondemand::value v;
ASSERT_SUCCESS((*iter).get(v));
std::string_view sv;
ASSERT_SUCCESS(v["key"].get_string().get(sv));
ASSERT_EQUAL(sv, "value2");
TEST_SUCCEED();
}
bool document_is_array_treated_as_object() {
TEST_START();
auto json = R"( [ {"key" : "value"} ] )"_padded;
@@ -855,6 +871,7 @@ namespace array_tests {
bool run() {
return
std_advance() &&
document_is_array_treated_as_object() &&
issue1977() &&
issue1876() &&
+22 -1
View File
@@ -1,3 +1,4 @@
#define SIMDJSON_VERBOSE_LOGGING 1
#include "simdjson.h"
#include "test_ondemand.h"
@@ -6,7 +7,6 @@ using namespace simdjson;
namespace object_tests {
using namespace std;
using simdjson::ondemand::json_type;
bool issue1979() {
TEST_START();
auto json = R"({
@@ -1015,6 +1015,26 @@ namespace object_tests {
TEST_SUCCEED();
}
bool manual_iterator_increment() {
// not recommended usage, but should work
TEST_START();
auto json = R"( {"1":1, "2":2, "3":3} )"_padded;
ondemand::parser parser;
ondemand::document doc;
ASSERT_SUCCESS(parser.iterate(json).get(doc));
ondemand::object obj;
ASSERT_SUCCESS(doc.get_object().get(obj));
std::cout << "object obtained.\n";
auto it = obj.begin();
*it; // essential !!!
++it;
auto field = *it;
std::string_view key;
ASSERT_SUCCESS(field.unescaped_key().get(key));
std::cout << "Key: " << key << std::endl;
ASSERT_EQUAL(key, "2");
TEST_SUCCEED();
}
bool issue1876() {
TEST_START();
auto json = R"( {} )"_padded;
@@ -1350,6 +1370,7 @@ namespace object_tests {
#endif
issue1974a() &&
issue1974b() &&
manual_iterator_increment() &&
issue1876a() &&
issue1876() &&
test_strager() &&