Remove document_iterator, document::iterator, ParsedJsonIterator
Keep ParsedJson::Iterator only, without template, in same form as it was in 0.2
This commit is contained in:
parent
26b15251e2
commit
a0bce440a6
2
Makefile
2
Makefile
|
@ -61,7 +61,7 @@ SRCHEADERS_WESTMERE=src/westmere/bitmanipulation.h src/westmere/bitmask.h src/we
|
|||
SRCHEADERS_SRC=src/isadetection.h src/jsoncharutils.h src/simdprune_tables.h src/implementation.cpp src/stage1_find_marks.cpp src/stage2_build_tape.cpp src/document_parser_callbacks.h
|
||||
SRCHEADERS=$(SRCHEADERS_SRC) $(SRCHEADERS_GENERIC) $(SRCHEADERS_ARM64) $(SRCHEADERS_HASWELL) $(SRCHEADERS_WESTMERE) $(SRCHEADERS_FALLBACK)
|
||||
|
||||
INCLUDEHEADERS=include/simdjson.h include/simdjson/common_defs.h include/simdjson/internal/jsonformatutils.h include/simdjson/jsonioutil.h include/simdjson/jsonparser.h include/simdjson/padded_string.h include/simdjson/inline/padded_string.h include/simdjson/document.h include/simdjson/inline/document.h include/simdjson/document_iterator.h include/simdjson/inline/document_iterator.h include/simdjson/document_stream.h include/simdjson/inline/document_stream.h include/simdjson/implementation.h include/simdjson/parsedjson.h include/simdjson/jsonstream.h include/simdjson/inline/jsonstream.h include/simdjson/portability.h include/simdjson/error.h include/simdjson/inline/error.h include/simdjson/simdjson.h include/simdjson/simdjson_version.h
|
||||
INCLUDEHEADERS=include/simdjson.h include/simdjson/common_defs.h include/simdjson/internal/jsonformatutils.h include/simdjson/jsonioutil.h include/simdjson/jsonparser.h include/simdjson/padded_string.h include/simdjson/inline/padded_string.h include/simdjson/document.h include/simdjson/inline/document.h include/simdjson/parsedjson_iterator.h include/simdjson/inline/parsedjson_iterator.h include/simdjson/document_stream.h include/simdjson/inline/document_stream.h include/simdjson/implementation.h include/simdjson/parsedjson.h include/simdjson/jsonstream.h include/simdjson/inline/jsonstream.h include/simdjson/portability.h include/simdjson/error.h include/simdjson/inline/error.h include/simdjson/simdjson.h include/simdjson/simdjson_version.h
|
||||
|
||||
ifeq ($(SIMDJSON_TEST_AMALGAMATED_HEADERS),1)
|
||||
HEADERS=singleheader/simdjson.h
|
||||
|
|
|
@ -26,9 +26,10 @@ BENCHMARK(twitter_count);
|
|||
|
||||
static void iterator_twitter_count(State& state) {
|
||||
// Prints the number of results in twitter.json
|
||||
document doc = document::load(JSON_TEST_PATH);
|
||||
padded_string json = padded_string::load(JSON_TEST_PATH);
|
||||
ParsedJson pj = build_parsed_json(json);
|
||||
for (auto _ : state) {
|
||||
document::iterator iter(doc);
|
||||
ParsedJson::Iterator iter(pj);
|
||||
// uint64_t result_count = doc["search_metadata"]["count"];
|
||||
if (!iter.move_to_key("search_metadata")) { return; }
|
||||
if (!iter.move_to_key("count")) { return; }
|
||||
|
@ -116,10 +117,11 @@ BENCHMARK(error_code_twitter_default_profile);
|
|||
|
||||
static void iterator_twitter_default_profile(State& state) {
|
||||
// Count unique users with a default profile.
|
||||
document doc = document::load(JSON_TEST_PATH);
|
||||
padded_string json = padded_string::load(JSON_TEST_PATH);
|
||||
ParsedJson pj = build_parsed_json(json);
|
||||
for (auto _ : state) {
|
||||
set<string_view> default_users;
|
||||
document::iterator iter(doc);
|
||||
ParsedJson::Iterator iter(pj);
|
||||
|
||||
// for (document::object tweet : doc["statuses"].as_array()) {
|
||||
if (!(iter.move_to_key("statuses") && iter.is_array())) { return; }
|
||||
|
@ -180,10 +182,11 @@ BENCHMARK(error_code_twitter_image_sizes);
|
|||
|
||||
static void iterator_twitter_image_sizes(State& state) {
|
||||
// Count unique image sizes
|
||||
document doc = document::load(JSON_TEST_PATH);
|
||||
padded_string json = padded_string::load(JSON_TEST_PATH);
|
||||
ParsedJson pj = build_parsed_json(json);
|
||||
for (auto _ : state) {
|
||||
set<tuple<uint64_t, uint64_t>> image_sizes;
|
||||
document::iterator iter(doc);
|
||||
ParsedJson::Iterator iter(pj);
|
||||
|
||||
// for (document::object tweet : doc["statuses"].as_array()) {
|
||||
if (!(iter.move_to_key("statuses") && iter.is_array())) { return; }
|
||||
|
|
|
@ -30,7 +30,7 @@ void print_vec(const std::vector<int64_t> &v) {
|
|||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void simdjson_scan(std::vector<int64_t> &answer, simdjson::document::iterator i) {
|
||||
void simdjson_scan(std::vector<int64_t> &answer, simdjson::ParsedJson::Iterator i) {
|
||||
while (i.move_forward()) {
|
||||
if (i.get_scope_type() == '{') {
|
||||
bool found_user = (i.get_string_length() == 4) &&
|
||||
|
@ -49,9 +49,9 @@ void simdjson_scan(std::vector<int64_t> &answer, simdjson::document::iterator i)
|
|||
}
|
||||
|
||||
__attribute__((noinline)) std::vector<int64_t>
|
||||
simdjson_just_dom(simdjson::document &doc) {
|
||||
simdjson_just_dom(simdjson::ParsedJson &pj) {
|
||||
std::vector<int64_t> answer;
|
||||
simdjson_scan(answer, doc);
|
||||
simdjson_scan(answer, pj);
|
||||
remove_duplicates(answer);
|
||||
return answer;
|
||||
}
|
||||
|
@ -59,8 +59,8 @@ simdjson_just_dom(simdjson::document &doc) {
|
|||
__attribute__((noinline)) std::vector<int64_t>
|
||||
simdjson_compute_stats(const simdjson::padded_string &p) {
|
||||
std::vector<int64_t> answer;
|
||||
auto [doc, error] = simdjson::document::parse(p);
|
||||
simdjson_scan(answer, doc);
|
||||
ParsedJson pj = simdjson::build_parsed_json(p);
|
||||
simdjson_scan(answer, pj);
|
||||
remove_duplicates(answer);
|
||||
return answer;
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ int main(int argc, char *argv[]) {
|
|||
volume, !just_data);
|
||||
BEST_TIME("sasjon (just parse) ", sasjon_just_parse(p), false, , repeat,
|
||||
volume, !just_data);
|
||||
auto [dsimdjson, dsimdjson_error] = simdjson::document::parse(p);
|
||||
ParsedJson dsimdjson = build_parsed_json(p);
|
||||
BEST_TIME("simdjson (just dom) ", simdjson_just_dom(dsimdjson).size(), size,
|
||||
, repeat, volume, !just_data);
|
||||
char *buffer = (char *)malloc(p.size());
|
||||
|
|
|
@ -50,7 +50,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
|||
if (!pj.is_valid()) {
|
||||
throw 1;
|
||||
}
|
||||
simdjson::ParsedJson::Iterator pjh(pj.doc);
|
||||
simdjson::ParsedJson::Iterator pjh(pj);
|
||||
if (pjh.is_ok()) {
|
||||
compute_dump(pjh);
|
||||
}
|
||||
|
|
|
@ -3,23 +3,23 @@ set(SIMDJSON_INCLUDE
|
|||
${SIMDJSON_INCLUDE_DIR}/simdjson.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/common_defs.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/compiler_check.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/document_iterator.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/document_stream.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/document.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/error.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/implementation.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document_stream.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document_iterator.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/inline/error.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/inline/jsonstream.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/inline/padded_string.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/inline/parsedjson_iterator.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/internal/jsonformatutils.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/jsonioutil.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/jsonparser.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/jsonstream.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/padded_string.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/parsedjson.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/parsedjson_iterator.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/portability.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/simdjson_version.h
|
||||
${SIMDJSON_INCLUDE_DIR}/simdjson/simdjson.h
|
||||
|
|
|
@ -12,18 +12,17 @@
|
|||
#include "simdjson/document_stream.h"
|
||||
|
||||
// Deprecated API
|
||||
#include "simdjson/parsedjsoniterator.h"
|
||||
#include "simdjson/jsonparser.h"
|
||||
#include "simdjson/parsedjson.h"
|
||||
#include "simdjson/parsedjson_iterator.h"
|
||||
#include "simdjson/jsonstream.h"
|
||||
#include "simdjson/document_iterator.h"
|
||||
|
||||
// Inline functions
|
||||
#include "simdjson/inline/document.h"
|
||||
#include "simdjson/inline/document_iterator.h"
|
||||
#include "simdjson/inline/document_stream.h"
|
||||
#include "simdjson/inline/error.h"
|
||||
#include "simdjson/inline/jsonstream.h"
|
||||
#include "simdjson/inline/padded_string.h"
|
||||
#include "simdjson/inline/parsedjson_iterator.h"
|
||||
|
||||
#endif // SIMDJSON_H
|
||||
|
|
|
@ -18,8 +18,6 @@ class tape_ref;
|
|||
|
||||
namespace simdjson {
|
||||
|
||||
template<size_t max_depth> class document_iterator;
|
||||
|
||||
/**
|
||||
* A parsed JSON document.
|
||||
*
|
||||
|
@ -68,9 +66,6 @@ public:
|
|||
class object_result;
|
||||
class stream_result;
|
||||
|
||||
// Nested classes. See definitions later in file.
|
||||
using iterator = document_iterator<DEFAULT_MAX_DEPTH>;
|
||||
|
||||
/**
|
||||
* Get the root element of this document as a JSON array.
|
||||
*/
|
||||
|
@ -1760,7 +1755,9 @@ public:
|
|||
WARN_UNUSED inline bool allocate_capacity(size_t capacity, size_t max_depth = DEFAULT_MAX_DEPTH) noexcept;
|
||||
|
||||
// type aliases for backcompat
|
||||
using Iterator = document::iterator;
|
||||
/** @deprecated Use the new DOM API instead */
|
||||
class Iterator;
|
||||
/** @deprecated Use simdjson_error instead */
|
||||
using InvalidJSON = simdjson_error;
|
||||
|
||||
// Next location to write to in the tape
|
||||
|
@ -1894,7 +1891,7 @@ private:
|
|||
inline const document &get_document() const noexcept(false);
|
||||
#endif // SIMDJSON_EXCEPTIONS
|
||||
|
||||
template<size_t max_depth> friend class document_iterator;
|
||||
friend class document::parser::Iterator;
|
||||
friend class document::stream;
|
||||
}; // class parser
|
||||
|
||||
|
|
|
@ -1,45 +1,39 @@
|
|||
#ifndef SIMDJSON_INLINE_DOCUMENT_ITERATOR_H
|
||||
#define SIMDJSON_INLINE_DOCUMENT_ITERATOR_H
|
||||
#ifndef SIMDJSON_INLINE_PARSEDJSON_ITERATOR_H
|
||||
#define SIMDJSON_INLINE_PARSEDJSON_ITERATOR_H
|
||||
|
||||
#include "simdjson/document_iterator.h"
|
||||
#include "simdjson/parsedjson_iterator.h"
|
||||
|
||||
namespace simdjson {
|
||||
|
||||
// Because of template weirdness, the actual class definition is inline in the document class
|
||||
|
||||
template <size_t max_depth>
|
||||
WARN_UNUSED bool document_iterator<max_depth>::is_ok() const {
|
||||
WARN_UNUSED bool ParsedJson::Iterator::is_ok() const {
|
||||
return location < tape_length;
|
||||
}
|
||||
|
||||
// useful for debugging purposes
|
||||
template <size_t max_depth>
|
||||
size_t document_iterator<max_depth>::get_tape_location() const {
|
||||
size_t ParsedJson::Iterator::get_tape_location() const {
|
||||
return location;
|
||||
}
|
||||
|
||||
// useful for debugging purposes
|
||||
template <size_t max_depth>
|
||||
size_t document_iterator<max_depth>::get_tape_length() const {
|
||||
size_t ParsedJson::Iterator::get_tape_length() const {
|
||||
return tape_length;
|
||||
}
|
||||
|
||||
// returns the current depth (start at 1 with 0 reserved for the fictitious root
|
||||
// node)
|
||||
template <size_t max_depth>
|
||||
size_t document_iterator<max_depth>::get_depth() const {
|
||||
size_t ParsedJson::Iterator::get_depth() const {
|
||||
return depth;
|
||||
}
|
||||
|
||||
// A scope is a series of nodes at the same depth, typically it is either an
|
||||
// object ({) or an array ([). The root node has type 'r'.
|
||||
template <size_t max_depth>
|
||||
uint8_t document_iterator<max_depth>::get_scope_type() const {
|
||||
uint8_t ParsedJson::Iterator::get_scope_type() const {
|
||||
return depth_index[depth].scope_type;
|
||||
}
|
||||
|
||||
template <size_t max_depth>
|
||||
bool document_iterator<max_depth>::move_forward() {
|
||||
bool ParsedJson::Iterator::move_forward() {
|
||||
if (location + 1 >= tape_length) {
|
||||
return false; // we are at the end!
|
||||
}
|
||||
|
@ -64,16 +58,14 @@ bool document_iterator<max_depth>::move_forward() {
|
|||
return true;
|
||||
}
|
||||
|
||||
template <size_t max_depth>
|
||||
void document_iterator<max_depth>::move_to_value() {
|
||||
void ParsedJson::Iterator::move_to_value() {
|
||||
// assume that we are on a key, so move by 1.
|
||||
location += 1;
|
||||
current_val = doc.tape[location];
|
||||
current_type = (current_val >> 56);
|
||||
}
|
||||
|
||||
template <size_t max_depth>
|
||||
bool document_iterator<max_depth>::move_to_key(const char *key) {
|
||||
bool ParsedJson::Iterator::move_to_key(const char *key) {
|
||||
if (down()) {
|
||||
do {
|
||||
const bool right_key = (strcmp(get_string(), key) == 0);
|
||||
|
@ -87,8 +79,7 @@ bool document_iterator<max_depth>::move_to_key(const char *key) {
|
|||
return false;
|
||||
}
|
||||
|
||||
template <size_t max_depth>
|
||||
bool document_iterator<max_depth>::move_to_key_insensitive(
|
||||
bool ParsedJson::Iterator::move_to_key_insensitive(
|
||||
const char *key) {
|
||||
if (down()) {
|
||||
do {
|
||||
|
@ -103,8 +94,7 @@ bool document_iterator<max_depth>::move_to_key_insensitive(
|
|||
return false;
|
||||
}
|
||||
|
||||
template <size_t max_depth>
|
||||
bool document_iterator<max_depth>::move_to_key(const char *key,
|
||||
bool ParsedJson::Iterator::move_to_key(const char *key,
|
||||
uint32_t length) {
|
||||
if (down()) {
|
||||
do {
|
||||
|
@ -120,8 +110,7 @@ bool document_iterator<max_depth>::move_to_key(const char *key,
|
|||
return false;
|
||||
}
|
||||
|
||||
template <size_t max_depth>
|
||||
bool document_iterator<max_depth>::move_to_index(uint32_t index) {
|
||||
bool ParsedJson::Iterator::move_to_index(uint32_t index) {
|
||||
if (down()) {
|
||||
uint32_t i = 0;
|
||||
for (; i < index; i++) {
|
||||
|
@ -137,7 +126,7 @@ bool document_iterator<max_depth>::move_to_index(uint32_t index) {
|
|||
return false;
|
||||
}
|
||||
|
||||
template <size_t max_depth> bool document_iterator<max_depth>::prev() {
|
||||
bool ParsedJson::Iterator::prev() {
|
||||
size_t target_location = location;
|
||||
to_start_scope();
|
||||
size_t npos = location;
|
||||
|
@ -161,7 +150,7 @@ template <size_t max_depth> bool document_iterator<max_depth>::prev() {
|
|||
return true;
|
||||
}
|
||||
|
||||
template <size_t max_depth> bool document_iterator<max_depth>::up() {
|
||||
bool ParsedJson::Iterator::up() {
|
||||
if (depth == 1) {
|
||||
return false; // don't allow moving back to root
|
||||
}
|
||||
|
@ -174,7 +163,7 @@ template <size_t max_depth> bool document_iterator<max_depth>::up() {
|
|||
return true;
|
||||
}
|
||||
|
||||
template <size_t max_depth> bool document_iterator<max_depth>::down() {
|
||||
bool ParsedJson::Iterator::down() {
|
||||
if (location + 1 >= tape_length) {
|
||||
return false;
|
||||
}
|
||||
|
@ -195,14 +184,13 @@ template <size_t max_depth> bool document_iterator<max_depth>::down() {
|
|||
return false;
|
||||
}
|
||||
|
||||
template <size_t max_depth>
|
||||
void document_iterator<max_depth>::to_start_scope() {
|
||||
void ParsedJson::Iterator::to_start_scope() {
|
||||
location = depth_index[depth].start_of_scope;
|
||||
current_val = doc.tape[location];
|
||||
current_type = (current_val >> 56);
|
||||
}
|
||||
|
||||
template <size_t max_depth> bool document_iterator<max_depth>::next() {
|
||||
bool ParsedJson::Iterator::next() {
|
||||
size_t npos;
|
||||
if ((current_type == '[') || (current_type == '{')) {
|
||||
// we need to jump
|
||||
|
@ -221,9 +209,12 @@ template <size_t max_depth> bool document_iterator<max_depth>::next() {
|
|||
return true;
|
||||
}
|
||||
|
||||
template <size_t max_depth>
|
||||
document_iterator<max_depth>::document_iterator(const document &doc_) noexcept
|
||||
: doc(doc_), depth(0), location(0), tape_length(0) {
|
||||
ParsedJson::Iterator::Iterator(const ParsedJson &pj) noexcept(false)
|
||||
: doc(pj.doc), depth(0), location(0), tape_length(0) {
|
||||
if (!pj.is_valid()) { throw simdjson_error(pj.error); }
|
||||
|
||||
max_depth = pj.max_depth();
|
||||
depth_index = new scopeindex_t[max_depth + 1];
|
||||
depth_index[0].start_of_scope = location;
|
||||
current_val = doc.tape[location++];
|
||||
current_type = (current_val >> 56);
|
||||
|
@ -241,38 +232,20 @@ document_iterator<max_depth>::document_iterator(const document &doc_) noexcept
|
|||
}
|
||||
}
|
||||
|
||||
#if SIMDJSON_EXCEPTIONS
|
||||
|
||||
template <size_t max_depth>
|
||||
document_iterator<max_depth>::document_iterator(const document::parser &parser) noexcept(false)
|
||||
: document_iterator(parser.get_document()) {}
|
||||
|
||||
#endif
|
||||
|
||||
template <size_t max_depth>
|
||||
document_iterator<max_depth>::document_iterator(
|
||||
const document_iterator &o) noexcept
|
||||
: doc(o.doc), depth(o.depth), location(o.location),
|
||||
ParsedJson::Iterator::Iterator(
|
||||
const ParsedJson::Iterator &o) noexcept
|
||||
: doc(o.doc), max_depth(o.depth), depth(o.depth), location(o.location),
|
||||
tape_length(o.tape_length), current_type(o.current_type),
|
||||
current_val(o.current_val) {
|
||||
depth_index = new scopeindex_t[max_depth+1];
|
||||
memcpy(depth_index, o.depth_index, (depth + 1) * sizeof(depth_index[0]));
|
||||
}
|
||||
|
||||
template <size_t max_depth>
|
||||
document_iterator<max_depth> &document_iterator<max_depth>::
|
||||
operator=(const document_iterator &o) noexcept {
|
||||
doc = o.doc;
|
||||
depth = o.depth;
|
||||
location = o.location;
|
||||
tape_length = o.tape_length;
|
||||
current_type = o.current_type;
|
||||
current_val = o.current_val;
|
||||
memcpy(depth_index, o.depth_index, (depth + 1) * sizeof(depth_index[0]));
|
||||
return *this;
|
||||
ParsedJson::Iterator::~Iterator() noexcept {
|
||||
if (depth_index) { delete[] depth_index; }
|
||||
}
|
||||
|
||||
template <size_t max_depth>
|
||||
bool document_iterator<max_depth>::print(std::ostream &os, bool escape_strings) const {
|
||||
bool ParsedJson::Iterator::print(std::ostream &os, bool escape_strings) const {
|
||||
if (!is_ok()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -318,8 +291,7 @@ bool document_iterator<max_depth>::print(std::ostream &os, bool escape_strings)
|
|||
return true;
|
||||
}
|
||||
|
||||
template <size_t max_depth>
|
||||
bool document_iterator<max_depth>::move_to(const char *pointer,
|
||||
bool ParsedJson::Iterator::move_to(const char *pointer,
|
||||
uint32_t length) {
|
||||
char *new_pointer = nullptr;
|
||||
if (pointer[0] == '#') {
|
||||
|
@ -378,8 +350,7 @@ bool document_iterator<max_depth>::move_to(const char *pointer,
|
|||
return found;
|
||||
}
|
||||
|
||||
template <size_t max_depth>
|
||||
bool document_iterator<max_depth>::relative_move_to(const char *pointer,
|
||||
bool ParsedJson::Iterator::relative_move_to(const char *pointer,
|
||||
uint32_t length) {
|
||||
if (length == 0) {
|
||||
// returns the whole document
|
||||
|
@ -496,4 +467,4 @@ bool document_iterator<max_depth>::relative_move_to(const char *pointer,
|
|||
|
||||
} // namespace simdjson
|
||||
|
||||
#endif // SIMDJSON_INLINE_DOCUMENT_ITERATOR_H
|
||||
#endif // SIMDJSON_INLINE_PARSEDJSON_ITERATOR_H
|
|
@ -1,5 +1,7 @@
|
|||
#ifndef SIMDJSON_DOCUMENT_ITERATOR_H
|
||||
#define SIMDJSON_DOCUMENT_ITERATOR_H
|
||||
// TODO Remove this -- deprecated API and files
|
||||
|
||||
#ifndef SIMDJSON_PARSEDJSON_ITERATOR_H
|
||||
#define SIMDJSON_PARSEDJSON_ITERATOR_H
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
@ -9,18 +11,16 @@
|
|||
#include <stdexcept>
|
||||
|
||||
#include "simdjson/document.h"
|
||||
#include "simdjson/parsedjson.h"
|
||||
#include "simdjson/internal/jsonformatutils.h"
|
||||
|
||||
namespace simdjson {
|
||||
|
||||
template <size_t max_depth> class document_iterator {
|
||||
class ParsedJson::Iterator {
|
||||
public:
|
||||
#if SIMDJSON_EXCEPTIONS
|
||||
document_iterator(const document::parser &parser) noexcept(false);
|
||||
#endif
|
||||
document_iterator(const document &doc) noexcept;
|
||||
document_iterator(const document_iterator &o) noexcept;
|
||||
document_iterator &operator=(const document_iterator &o) noexcept;
|
||||
inline Iterator(const ParsedJson &parser) noexcept(false);
|
||||
inline Iterator(const Iterator &o) noexcept;
|
||||
inline ~Iterator() noexcept;
|
||||
|
||||
inline bool is_ok() const;
|
||||
|
||||
|
@ -175,7 +175,7 @@ public:
|
|||
// referenced is undefined, and evaluation fails". Here we just return the
|
||||
// first corresponding value. The length parameter is the length of the
|
||||
// jsonpointer string ('pointer').
|
||||
bool move_to(const char *pointer, uint32_t length);
|
||||
inline bool move_to(const char *pointer, uint32_t length);
|
||||
|
||||
// Moves the iterator to the value corresponding to the json pointer.
|
||||
// Always search from the root of the document.
|
||||
|
@ -198,7 +198,7 @@ public:
|
|||
// Representation is not supported here. Also, in case of failure, we are
|
||||
// left pointing at the closest value it could reach. For these reasons it
|
||||
// is private. It exists because it is used by move_to().
|
||||
bool relative_move_to(const char *pointer, uint32_t length);
|
||||
inline bool relative_move_to(const char *pointer, uint32_t length);
|
||||
|
||||
public:
|
||||
// throughout return true if we can do the navigation, false
|
||||
|
@ -245,7 +245,7 @@ public:
|
|||
// the start of our current scope; always succeeds
|
||||
|
||||
// print the node we are currently pointing at
|
||||
bool print(std::ostream &os, bool escape_strings = true) const;
|
||||
inline bool print(std::ostream &os, bool escape_strings = true) const;
|
||||
typedef struct {
|
||||
size_t start_of_scope;
|
||||
uint8_t scope_type;
|
||||
|
@ -253,14 +253,15 @@ public:
|
|||
|
||||
private:
|
||||
const document &doc;
|
||||
size_t max_depth;
|
||||
size_t depth;
|
||||
size_t location; // our current location on a tape
|
||||
size_t tape_length;
|
||||
uint8_t current_type;
|
||||
uint64_t current_val;
|
||||
scopeindex_t depth_index[max_depth];
|
||||
scopeindex_t *depth_index;
|
||||
};
|
||||
|
||||
} // namespace simdjson
|
||||
|
||||
#endif // SIMDJSON_DOCUMENT_ITERATOR_H
|
||||
#endif
|
|
@ -1,8 +0,0 @@
|
|||
// TODO Remove this -- deprecated API and files
|
||||
|
||||
#ifndef SIMDJSON_PARSEDJSONITERATOR_H
|
||||
#define SIMDJSON_PARSEDJSONITERATOR_H
|
||||
|
||||
#include "simdjson/document_iterator.h"
|
||||
|
||||
#endif
|
|
@ -42,18 +42,18 @@ namespace number_tests {
|
|||
bool small_integers() {
|
||||
std::cout << __func__ << std::endl;
|
||||
char buf[1024];
|
||||
simdjson::document::parser parser;
|
||||
simdjson::ParsedJson pj;
|
||||
for (int m = 10; m < 20; m++) {
|
||||
for (int i = -1024; i < 1024; i++) {
|
||||
auto n = sprintf(buf, "%*d", m, i);
|
||||
buf[n] = '\0';
|
||||
fflush(NULL);
|
||||
auto [doc, error] = parser.parse(buf, n);
|
||||
auto error = simdjson::json_parse(buf, n, pj);
|
||||
if (error) {
|
||||
printf("Could not parse '%s': %s\n", buf, simdjson::error_message(error));
|
||||
printf("Could not parse '%s': %s\n", buf, simdjson::error_message(error).c_str());
|
||||
return false;
|
||||
}
|
||||
simdjson::document::iterator iter(doc);
|
||||
simdjson::ParsedJson::Iterator iter(pj);
|
||||
if(!iter.is_number()) {
|
||||
printf("Root should be number\n");
|
||||
return false;
|
||||
|
@ -77,19 +77,19 @@ namespace number_tests {
|
|||
bool powers_of_two() {
|
||||
std::cout << __func__ << std::endl;
|
||||
char buf[1024];
|
||||
simdjson::document::parser parser;
|
||||
simdjson::ParsedJson pj;
|
||||
int maxulp = 0;
|
||||
for (int i = -1075; i < 1024; ++i) {// large negative values should be zero.
|
||||
double expected = pow(2, i);
|
||||
auto n = sprintf(buf, "%.*e", std::numeric_limits<double>::max_digits10 - 1, expected);
|
||||
buf[n] = '\0';
|
||||
fflush(NULL);
|
||||
auto [doc, error] = parser.parse(buf, n);
|
||||
auto error = simdjson::json_parse(buf, n, pj);
|
||||
if (error) {
|
||||
printf("Could not parse '%s': %s\n", buf, simdjson::error_message(error));
|
||||
printf("Could not parse '%s': %s\n", buf, simdjson::error_message(error).c_str());
|
||||
return false;
|
||||
}
|
||||
simdjson::document::iterator iter(doc);
|
||||
simdjson::ParsedJson::Iterator iter(pj);
|
||||
if(!iter.is_number()) {
|
||||
printf("Root should be number\n");
|
||||
return false;
|
||||
|
@ -214,17 +214,17 @@ namespace number_tests {
|
|||
bool powers_of_ten() {
|
||||
std::cout << __func__ << std::endl;
|
||||
char buf[1024];
|
||||
simdjson::document::parser parser;
|
||||
simdjson::ParsedJson pj;
|
||||
for (int i = -1000000; i <= 308; ++i) {// large negative values should be zero.
|
||||
auto n = sprintf(buf,"1e%d", i);
|
||||
buf[n] = '\0';
|
||||
fflush(NULL);
|
||||
auto [doc, error] = parser.parse(buf, n);
|
||||
auto error = simdjson::json_parse(buf, n, pj);
|
||||
if (error) {
|
||||
printf("Could not parse '%s': %s\n", buf, simdjson::error_message(error));
|
||||
printf("Could not parse '%s': %s\n", buf, simdjson::error_message(error).c_str());
|
||||
return false;
|
||||
}
|
||||
simdjson::document::iterator iter(doc);
|
||||
simdjson::ParsedJson::Iterator iter(pj);
|
||||
if(!iter.is_number()) {
|
||||
printf("Root should be number\n");
|
||||
return false;
|
||||
|
@ -363,12 +363,12 @@ namespace document_tests {
|
|||
fflush(NULL);
|
||||
}
|
||||
counter++;
|
||||
auto ok1 = json_parse(rec.c_str(), rec.length(), parser);
|
||||
auto ok1 = simdjson::json_parse(rec.c_str(), rec.length(), parser);
|
||||
if (ok1 != 0 || !parser.is_valid()) {
|
||||
printf("Something is wrong in skyprophet_test: %s.\n", rec.c_str());
|
||||
return false;
|
||||
}
|
||||
auto ok2 = json_parse(rec, parser);
|
||||
auto ok2 = simdjson::json_parse(rec, parser);
|
||||
if (ok2 != 0 || !parser.is_valid()) {
|
||||
printf("Something is wrong in skyprophet_test: %s.\n", rec.c_str());
|
||||
return false;
|
||||
|
@ -461,13 +461,13 @@ namespace document_stream_tests {
|
|||
simdjson::JsonStream<simdjson::padded_string> js{str, batch_size};
|
||||
int parse_res = simdjson::SUCCESS_AND_HAS_MORE;
|
||||
size_t count = 0;
|
||||
simdjson::document::parser parser;
|
||||
simdjson::ParsedJson pj;
|
||||
while (parse_res == simdjson::SUCCESS_AND_HAS_MORE) {
|
||||
parse_res = js.json_parse(parser);
|
||||
parse_res = js.json_parse(pj);
|
||||
if (parse_res != simdjson::SUCCESS && parse_res != simdjson::SUCCESS_AND_HAS_MORE) {
|
||||
break;
|
||||
}
|
||||
simdjson::document::iterator iter(parser.doc);
|
||||
simdjson::ParsedJson::Iterator iter(pj);
|
||||
if(!iter.is_object()) {
|
||||
printf("Root should be object\n");
|
||||
return false;
|
||||
|
@ -525,13 +525,13 @@ namespace document_stream_tests {
|
|||
simdjson::JsonStream<simdjson::padded_string> js{str, batch_size};
|
||||
int parse_res = simdjson::SUCCESS_AND_HAS_MORE;
|
||||
size_t count = 0;
|
||||
simdjson::document::parser parser;
|
||||
simdjson::ParsedJson pj;
|
||||
while (parse_res == simdjson::SUCCESS_AND_HAS_MORE) {
|
||||
parse_res = js.json_parse(parser);
|
||||
parse_res = js.json_parse(pj);
|
||||
if (parse_res != simdjson::SUCCESS && parse_res != simdjson::SUCCESS_AND_HAS_MORE) {
|
||||
break;
|
||||
}
|
||||
simdjson::document::iterator iter(parser.doc);
|
||||
simdjson::ParsedJson::Iterator iter(pj);
|
||||
if(!iter.is_object()) {
|
||||
printf("Root should be object\n");
|
||||
return false;
|
||||
|
@ -842,12 +842,12 @@ namespace dom_api_tests {
|
|||
"}"
|
||||
"}";
|
||||
|
||||
auto [doc, error] = simdjson::document::parse(json);
|
||||
if (error) {
|
||||
printf("Could not parse '%s': %s\n", json.data(), simdjson::error_message(error));
|
||||
ParsedJson pj = build_parsed_json(json);
|
||||
if (pj.error) {
|
||||
printf("Could not parse '%s': %s\n", json.data(), simdjson::error_message(pj.error));
|
||||
return false;
|
||||
}
|
||||
simdjson::document::iterator iter(doc);
|
||||
simdjson::ParsedJson::Iterator iter(pj);
|
||||
if(!iter.is_object()) {
|
||||
printf("Root should be object\n");
|
||||
return false;
|
||||
|
|
|
@ -35,7 +35,7 @@ static void parse_and_validate(const std::string src, T expected) {
|
|||
auto json = build_parsed_json(pstr);
|
||||
|
||||
ASSERT(json.is_valid());
|
||||
ParsedJson::Iterator it{json.doc};
|
||||
ParsedJson::Iterator it{json};
|
||||
ASSERT(it.down());
|
||||
ASSERT(it.next());
|
||||
bool result;
|
||||
|
@ -59,7 +59,7 @@ static bool parse_and_check_signed(const std::string src) {
|
|||
auto json = build_parsed_json(pstr);
|
||||
|
||||
ASSERT(json.is_valid());
|
||||
document::iterator it{json.doc};
|
||||
ParsedJson::Iterator it{json};
|
||||
ASSERT(it.down());
|
||||
ASSERT(it.next());
|
||||
return it.is_integer() && it.is_number();
|
||||
|
@ -71,7 +71,7 @@ static bool parse_and_check_unsigned(const std::string src) {
|
|||
auto json = build_parsed_json(pstr);
|
||||
|
||||
ASSERT(json.is_valid());
|
||||
document::iterator it{json.doc};
|
||||
ParsedJson::Iterator it{json};
|
||||
ASSERT(it.down());
|
||||
ASSERT(it.next());
|
||||
return it.is_unsigned_integer() && it.is_number();
|
||||
|
|
|
@ -101,14 +101,6 @@ bool validate(const char *dirname) {
|
|||
printf("size of file in bytes: %zu \n", json.size());
|
||||
everything_fine = false;
|
||||
}
|
||||
if(!error) {
|
||||
// issue 570, we just want to check for segfault
|
||||
simdjson::document::parser parser;
|
||||
for (const simdjson::document &doc : parser.load_many(fullpath)) {
|
||||
auto iter = simdjson::document::iterator(doc);
|
||||
//do something
|
||||
}
|
||||
}
|
||||
free(fullpath);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue