Loop over the nodes in the next list instead of making a recursive call. Otherwise, together with the recursive call on the child nodes, the call stack might exceed the system limit, e.g. on s390x where the maximum size a process may lock into memory is quite small (8192 kB).
This seems fine except for the one minor naming comment. I do wonder if just switching the recursion order would work too, but this commit should be even better.
Loop over the nodes in the next list instead of making a recursive call. Otherwise, together with the recursive call on the child nodes, the call stack might exceed the system limit, e.g. on s390x where the maximum size a process may lock into memory is quite small (8192 kB).