-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Iterative destruction of JSON containers (objects and arrays) #1431
Iterative destruction of JSON containers (objects and arrays) #1431
Conversation
…) instead of implicit recursive destruction in order to avoid stack overflows for deeply nested hierarchies
ed953be
to
d5ac351
Compare
Thanks for the PR! |
I applaud your effort here and the PR looks correct. However I found it very difficult to audit and read -- which makes me worry that it will be difficult to maintain. The hardest thing here is that there are many levels of indentation, and worse, two nested while loops. I think splitting out the loops into separate functions (and avoiding having to split the top-level switch-case) makes it much easier to audit and understand what it's doing. Eg, a rough sketch:
And then:
|
@jaredgrubb Thank you very much for your feedback and sorry for the late reply! I changed the code pretty much exactly according to your suggestion and added a few comments. It is indeed much better readable now 👍 |
b4f70c9
to
df42d48
Compare
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Deeply nested JSON hierarchies may lead to stack overflows during destruction, since JSON containers call the destructor of their children recursively (see issue #832).
This change provides an iterative destruction of JSON containers, avoiding a deep call stack by maintaining an explicit stack on the heap.