diff --git a/include/jsoncons/json_decoder.hpp b/include/jsoncons/json_decoder.hpp index 806080752f..ecfb502ccb 100644 --- a/include/jsoncons/json_decoder.hpp +++ b/include/jsoncons/json_decoder.hpp @@ -66,7 +66,8 @@ class json_decoder final : public basic_json_visitor public: json_decoder(const allocator_type& alloc = allocator_type(), - const temp_allocator_type& temp_alloc = temp_allocator_type()) + const temp_allocator_type& temp_alloc = temp_allocator_type(), + size_t items_count = 1000) : allocator_(alloc), result_(), index_(0), @@ -75,9 +76,7 @@ class json_decoder final : public basic_json_visitor structure_stack_(temp_alloc), is_valid_(false) { - item_stack_.reserve(1000); - structure_stack_.reserve(100); - structure_stack_.emplace_back(structure_type::root_t, 0); + Initialize(items_count, items_count / 10); } json_decoder(temp_allocator_arg_t, @@ -90,9 +89,7 @@ class json_decoder final : public basic_json_visitor structure_stack_(temp_alloc), is_valid_(false) { - item_stack_.reserve(1000); - structure_stack_.reserve(100); - structure_stack_.emplace_back(structure_type::root_t, 0); + Initialize(1000,100); } #if !defined(JSONCONS_NO_DEPRECATED) @@ -134,6 +131,13 @@ class json_decoder final : public basic_json_visitor private: + void Initialize(size_t items_count, size_t structures_count) + { + item_stack_.reserve(items_count); + structure_stack_.reserve(structures_count); + structure_stack_.emplace_back(structure_type::root_t, 0); + } + void visit_flush() override { }