Remove array::has_next
This commit is contained in:
parent
2b3c4c68e4
commit
6451e5e7d1
src/generic/ondemand
|
@ -41,23 +41,22 @@ namespace ondemand {
|
|||
//
|
||||
|
||||
simdjson_really_inline array::array() noexcept = default;
|
||||
simdjson_really_inline array::array(json_iterator_ref &&_iter, bool has_value) noexcept
|
||||
: iter{std::forward<json_iterator_ref>(_iter)}, has_next{has_value}, error{SUCCESS}
|
||||
simdjson_really_inline array::array(json_iterator_ref &&_iter) noexcept
|
||||
: iter{std::forward<json_iterator_ref>(_iter)}, error{SUCCESS}
|
||||
{
|
||||
}
|
||||
simdjson_really_inline array::array(array &&other) noexcept
|
||||
: iter{std::forward<array>(other).iter}, has_next{other.has_next}, error{other.error}
|
||||
: iter{std::forward<array>(other).iter}, error{other.error}
|
||||
{
|
||||
}
|
||||
simdjson_really_inline array &array::operator=(array &&other) noexcept {
|
||||
iter = std::forward<array>(other).iter;
|
||||
has_next = other.has_next;
|
||||
error = other.error;
|
||||
return *this;
|
||||
}
|
||||
|
||||
simdjson_really_inline array::~array() noexcept {
|
||||
if (!error && has_next && iter.is_alive()) {
|
||||
if (iter.is_alive()) {
|
||||
logger::log_event(*iter, "unfinished", "array");
|
||||
iter->skip_container();
|
||||
iter.release();
|
||||
|
@ -67,10 +66,12 @@ simdjson_really_inline array::~array() noexcept {
|
|||
simdjson_really_inline simdjson_result<array> array::start(json_iterator_ref &&iter) noexcept {
|
||||
bool has_value;
|
||||
SIMDJSON_TRY( iter->start_array().get(has_value) );
|
||||
return array(std::forward<json_iterator_ref>(iter), has_value);
|
||||
if (!has_value) { iter.release(); }
|
||||
return array(std::forward<json_iterator_ref>(iter));
|
||||
}
|
||||
simdjson_really_inline array array::started(json_iterator_ref &&iter) noexcept {
|
||||
return array(std::forward<json_iterator_ref>(iter), iter->started_array());
|
||||
if (!iter->started_array()) { iter.release(); }
|
||||
return array(std::forward<json_iterator_ref>(iter));
|
||||
}
|
||||
simdjson_really_inline array::iterator array::begin() noexcept {
|
||||
return *this;
|
||||
|
@ -79,12 +80,6 @@ simdjson_really_inline array::iterator array::end() noexcept {
|
|||
return *this;
|
||||
}
|
||||
|
||||
simdjson_really_inline error_code array::report_error() noexcept {
|
||||
SIMDJSON_ASSUME(error);
|
||||
has_next = false;
|
||||
return error;
|
||||
}
|
||||
|
||||
simdjson_really_inline array::iterator::iterator(array &_a) noexcept : a{&_a} {}
|
||||
|
||||
simdjson_really_inline array::iterator::iterator() noexcept = default;
|
||||
|
@ -92,18 +87,19 @@ simdjson_really_inline array::iterator::iterator(const array::iterator &_a) noex
|
|||
simdjson_really_inline array::iterator &array::iterator::operator=(const array::iterator &_a) noexcept = default;
|
||||
|
||||
simdjson_really_inline simdjson_result<value> array::iterator::operator*() noexcept {
|
||||
if (a->error) { return a->report_error(); }
|
||||
if (a->error) { a->iter.release(); return a->error; }
|
||||
return value::start(a->iter.borrow());
|
||||
}
|
||||
simdjson_really_inline bool array::iterator::operator==(const array::iterator &other) noexcept {
|
||||
return !(*this != other);
|
||||
}
|
||||
simdjson_really_inline bool array::iterator::operator!=(const array::iterator &) noexcept {
|
||||
return a->has_next;
|
||||
return a->iter.is_alive();
|
||||
}
|
||||
simdjson_really_inline array::iterator &array::iterator::operator++() noexcept {
|
||||
a->error = a->iter->has_next_element().get(a->has_next); // If there's an error, has_next stays true.
|
||||
if (!a->error && !a->has_next) { a->iter.release(); }
|
||||
bool has_value;
|
||||
a->error = a->iter->has_next_element().get(has_value); // If there's an error, has_next stays true.
|
||||
if (!(a->error || has_value)) { a->iter.release(); }
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,19 +61,13 @@ protected:
|
|||
*/
|
||||
static simdjson_really_inline array started(json_iterator_ref &&iter) noexcept;
|
||||
|
||||
/**
|
||||
* Report the current error and set finished so it won't be reported again.
|
||||
*/
|
||||
simdjson_really_inline error_code report_error() noexcept;
|
||||
|
||||
/**
|
||||
* Internal array creation. Call array::start() or array::started() instead of this.
|
||||
*
|
||||
* @param doc The document containing the array. iter->depth must already be incremented to
|
||||
* reflect the array's depth. The iterator must be just after the opening `[`.
|
||||
* @param has_value Whether the array has a value (false means empty array).
|
||||
*/
|
||||
simdjson_really_inline array(json_iterator_ref &&iter, bool has_value) noexcept;
|
||||
simdjson_really_inline array(json_iterator_ref &&iter) noexcept;
|
||||
|
||||
/**
|
||||
* Document containing this array.
|
||||
|
@ -82,14 +76,6 @@ protected:
|
|||
* is first used, and never changes afterwards.
|
||||
*/
|
||||
json_iterator_ref iter{};
|
||||
/**
|
||||
* Whether we have anything to yield.
|
||||
*
|
||||
* PERF NOTE: we hope this will be elided into inline control flow, as it is true for all
|
||||
* iterations except the last, and compilers with SSA optimization can sometimes do last-iteration
|
||||
* optimization.
|
||||
*/
|
||||
bool has_next{};
|
||||
/**
|
||||
* Error, if there is one. Errors are only yielded once.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue