From: Nicholas Clark Date: Thu, 12 May 2011 14:04:17 +0000 (+0100) Subject: Count HvNAME(), the HV "aux" struct, and the mro_meta struct. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-Size.git;a=commitdiff_plain;h=78037efb12f431d87eb4f21faead41323add6ef9 Count HvNAME(), the HV "aux" struct, and the mro_meta struct. --- diff --git a/CHANGES b/CHANGES index b578e9e..969b9fa 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,7 @@ Revision history for Perl extension Devel::Size. * Split out HEK size calculation into hek_size(). Add the shared HE overhead. * Handle shared hash key scalars correctly. * GvNAME() is shared from 5.10 onwards. + * Count HvNAME(), the HV "aux" struct, and the mro_meta struct. 0.76 2011-05-11 nicholas * Just fix the version number in the line below. diff --git a/Size.xs b/Size.xs index e588b67..2d0fc53 100644 --- a/Size.xs +++ b/Size.xs @@ -741,6 +741,30 @@ sv_size(pTHX_ struct state *const st, const SV * const orig_thing, } } } +#ifdef HvAUX + if (SvOOK(thing)) { + /* This direct access is arguably "naughty": */ + struct mro_meta *meta = HvAUX(thing)->xhv_mro_meta; + st->total_size += sizeof(struct xpvhv_aux); + hek_size(aTHX_ st, HvNAME_HEK(thing), 1); + if (meta) { + st->total_size += sizeof(struct mro_meta); + sv_size(aTHX_ st, (SV *)meta->mro_nextmethod, TOTAL_SIZE_RECURSION); +#if PERL_VERSION > 10 || (PERL_VERSION == 10 && PERL_SUBVERSION > 0) + sv_size(aTHX_ st, (SV *)meta->isa, TOTAL_SIZE_RECURSION); +#endif +#if PERL_VERSION > 10 + sv_size(aTHX_ st, (SV *)meta->mro_linear_all, TOTAL_SIZE_RECURSION); + sv_size(aTHX_ st, meta->mro_linear_current, TOTAL_SIZE_RECURSION); +#else + sv_size(aTHX_ st, (SV *)meta->mro_linear_dfs, TOTAL_SIZE_RECURSION); + sv_size(aTHX_ st, (SV *)meta->mro_linear_c3, TOTAL_SIZE_RECURSION); +#endif + } + } +#else + check_new_and_strlen(st, HvNAME_get(thing)); +#endif TAG;break; diff --git a/t/basic.t b/t/basic.t index 80a03ec..6c68bfb 100644 --- a/t/basic.t +++ b/t/basic.t @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::More tests => 26; +use Test::More tests => 30; use strict; use Devel::Size qw(size total_size); @@ -145,3 +145,29 @@ sub shared_hash_keys { is ($small, $big, 'The "shared" part of shared hash keys is spotted'); } } + +{ + use vars '%DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG'; + my $hash_size = total_size(\%DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG); + cmp_ok($hash_size, '>', 0, 'Hash size is sane'); + my $stash_size + = total_size(\%DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG::); + cmp_ok($stash_size, '>', + $hash_size + length 'DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG', + 'Stash size is larger than hash size plus length of the name'); +} + +{ + my %h = (Perl => 'Rules'); + my $hash_size = total_size(\%h); + cmp_ok($hash_size, '>', 0, 'Hash size is sane'); + my $a = keys %h; + if ($] < 5.010) { + is(total_size(\%h), $hash_size, + "Creating iteration state doesn't need to allocate storage"); + # because all hashes carry the overhead of this storage from creation + } else { + cmp_ok(total_size(\%h), '>', $hash_size, + 'Creating iteration state allocates storage'); + } +}