Skip to content

Commit 0b9df6d

Browse files
author
Daniel Lemire
committed
It turns out that we need fairly complicated logic.
1 parent 803b0c4 commit 0b9df6d

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

include/simdjson/inline/parser.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,23 @@ inline error_code parser::allocate(size_t capacity, size_t max_depth) noexcept {
151151
// Reallocate implementation and document if needed
152152
//
153153
error_code err;
154+
//
154155
// It is possible that we change max_depth without touching capacity, in
155156
// which case, we do not want to reallocate the document buffers.
156-
if (implementation->capacity() != capacity || !doc.tape) {
157-
err = doc.allocate(capacity);
158-
if (err) { return err; }
159-
}
157+
//
158+
bool need_doc_allocation{false};
160159
if (implementation) {
160+
need_doc_allocation = implementation->capacity() != capacity || !doc.tape;
161161
err = implementation->allocate(capacity, max_depth);
162162
} else {
163+
need_doc_allocation = true;
163164
err = simdjson::active_implementation->create_dom_parser_implementation(capacity, max_depth, implementation);
164165
}
165166
if (err) { return err; }
166-
167+
if (need_doc_allocation) {
168+
err = doc.allocate(capacity);
169+
if (err) { return err; }
170+
}
167171
return SUCCESS;
168172
}
169173

0 commit comments

Comments
 (0)