This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make hv freeing iterative rather than recursive
authorDavid Mitchell <davem@iabyn.com>
Wed, 11 May 2011 11:07:14 +0000 (12:07 +0100)
committerDavid Mitchell <davem@iabyn.com>
Thu, 19 May 2011 13:49:43 +0000 (14:49 +0100)
commit104d7b699c0dfac5bf91d1c05f84b3822c2c3e88
tree623ca2dceaaf3cd9e01f1c175b840ee2e4f001d6
parente0171a1a31b0610ebdf32920b0159c22c37e4691
make hv freeing iterative rather than recursive

make sv_clear() iteratively free the elements of a hash, rather than
recursing. This stops freeing deeply nested hash of hash structures from
blowing the stack.

This commit is relatively straightfoward, now that
a) the infrastruure is already in place in sv_clear to iteratively
   free AVs;
b) the long sequence of commits leading up to this has provided us with
    the hfree_next_entry() function, which returns just the next sv in the
    hash that needs freeing.

When starting to free a new hash, we have to save the old value of iter_sv
somewhere; we do this by sticking it in the unused SvSTASH slot of the HV.
This slot shouldn't get messed with, since, but this time we've already
called the destructor on this object, and we should have a refcount of
zero, so no destructor should be able to see us to rebless us.

Ideally we'd like to be able to save the old index into HvARRAY when
freeing a new HV, but I couldn't think of anywhere to hide it.
So we get sub-optimal scanning of the parent's HvARRAY when freeing hashes
of hashes.
hv.c
sv.c