mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
b648a5fc0a
* add std::ranges support for On-Demand API (#2382) Add zero-cost range wrappers (array_range, object_range) that satisfy std::ranges::input_range, enabling std::views::transform and other C++20 range adaptors with the On-Demand parser. Uses direct forwarding via simdjson_inline with no value buffering, avoiding the per-element overhead (~20%) of the previous approach. Guarded by SIMDJSON_SUPPORTS_RANGES. * fix: replace non-ASCII em dash in test comment The just_ascii CI check flags any non-ASCII characters in source files. * let us see what we get with this... * minor tweak * minor update * update doc --------- Co-authored-by: Justin Li <justin53@bu.edu>
33 lines
951 B
C++
33 lines
951 B
C++
#pragma once
|
|
|
|
#if SIMDJSON_EXCEPTIONS && SIMDJSON_SUPPORTS_RANGES
|
|
|
|
#include "large_random.h"
|
|
|
|
namespace large_random {
|
|
|
|
using namespace simdjson;
|
|
|
|
// Identical to simdjson_ondemand but uses get_range() for iteration.
|
|
// Demonstrates that the ranges wrapper has zero per-element overhead.
|
|
struct simdjson_ondemand_ranges {
|
|
static constexpr diff_flags DiffFlags = diff_flags::NONE;
|
|
|
|
ondemand::parser parser{};
|
|
|
|
bool run(simdjson::padded_string &json, std::vector<point> &result) {
|
|
auto doc = parser.iterate(json);
|
|
for (auto coord_result : ondemand::get_range(doc.get_array())) {
|
|
ondemand::object coord = coord_result;
|
|
result.emplace_back(json_benchmark::point{coord.find_field("x"), coord.find_field("y"), coord.find_field("z")});
|
|
}
|
|
return true;
|
|
}
|
|
};
|
|
|
|
BENCHMARK_TEMPLATE(large_random, simdjson_ondemand_ranges)->UseManualTime();
|
|
|
|
} // namespace large_random
|
|
|
|
#endif // SIMDJSON_EXCEPTIONS && SIMDJSON_SUPPORTS_RANGES
|