Make serializer dump() non-recursive#4439
Conversation
|
Unfortunately has some compile errors on MSVC etc. Can update and fix if you like this direction -
|
gregmarr
left a comment
There was a problem hiding this comment.
I'm not saying whether this is something that should be pursued or not, but in case it is, a couple initial observations.
| if (pretty_print) | ||
| while (!stack.empty()) | ||
| { | ||
| const dump_state& state = stack.back(); |
There was a problem hiding this comment.
By taking a reference here, you end up with a dangling reference when you do pop_back(). Even if you don't use state again after the pop_back(), you are referring to the BasicJsonType inside it with val. It's probably better to store a BasicJsonType * in the state, so you don't have to worry about referenceds to references, and then you can do this:
const BasicJsonType* val = stack.back().val;
const unsigned int current_indent = stack.back().new_indent;
const unsigned int offset = stack.back().offset;
auto iterator = stack.back().iterator;
stack.pop_back();
| const unsigned int offset; | ||
| const decltype(start_val.m_data.m_value.object->cbegin()) iterator; | ||
| }; | ||
| std::vector<dump_state> stack; |
There was a problem hiding this comment.
A std::stack would probably be a better choice.
9459221 to
6fdba5b
Compare
|
I very much like this fix here! It was on my todo list as well. |
|
This pull request has been marked as stale because it has had no activity for 30 days. While we won’t close it automatically, we encourage you to update or comment if it is still relevant. Keeping pull requests active and up-to-date helps us review and merge changes more efficiently. Thank you for your contributions! |
This allows printing very deep trees without running out of stack.