From 803b0c4bdbaeb8912fc608041f60e3bdb07abb6d Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Wed, 17 Jun 2020 11:00:13 -0400 Subject: [PATCH] Light touch. --- include/simdjson/inline/parser.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/simdjson/inline/parser.h b/include/simdjson/inline/parser.h index 76b8d5dfe..7030f748e 100644 --- a/include/simdjson/inline/parser.h +++ b/include/simdjson/inline/parser.h @@ -151,6 +151,12 @@ inline error_code parser::allocate(size_t capacity, size_t max_depth) noexcept { // Reallocate implementation and document if needed // error_code err; + // It is possible that we change max_depth without touching capacity, in + // which case, we do not want to reallocate the document buffers. + if (implementation->capacity() != capacity || !doc.tape) { + err = doc.allocate(capacity); + if (err) { return err; } + } if (implementation) { err = implementation->allocate(capacity, max_depth); } else { @@ -158,7 +164,7 @@ inline error_code parser::allocate(size_t capacity, size_t max_depth) noexcept { } if (err) { return err; } - return doc.allocate(capacity); + return SUCCESS; } WARN_UNUSED