X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=Size.xs;h=02c16c33aacbf8a0f39a34175795a2d01200f32b;hb=b98fcdb93f447c4f556f859c61b15c5fdd502bee;hp=248637c28238cb5d325eeb8dc3f74187ec197719;hpb=5c2e1b1290f2cc1677c307216577384513f45430;p=p5sagit%2FDevel-Size.git diff --git a/Size.xs b/Size.xs index 248637c..02c16c3 100644 --- a/Size.xs +++ b/Size.xs @@ -153,8 +153,7 @@ UV thing_size(SV *orig_thing, HV *tracking_hash) { if (cur_entry->hent_hek) { /* Hash keys can be shared. Have we seen this before? */ if (check_new(tracking_hash, cur_entry->hent_hek)) { - total_size += sizeof(HEK); - total_size += cur_entry->hent_hek->hek_len - 1; + total_size += HEK_BASESIZE + cur_entry->hent_hek->hek_len + 2; } } cur_entry = cur_entry->hent_next; @@ -172,13 +171,18 @@ UV thing_size(SV *orig_thing, HV *tracking_hash) { total_size += magic_size(thing, tracking_hash); total_size += sizeof(XPVGV); total_size += GvNAMELEN(thing); + /* Is there a file? */ + if (GvFILE(thing)) { + if (check_new(tracking_hash, GvFILE(thing))) { + total_size += strlen(GvFILE(thing)); + } + } /* Is there something hanging off the glob? */ if (GvGP(thing)) { if (check_new(tracking_hash, GvGP(thing))) { total_size += sizeof(GP); } } - carp("GC isn't complete"); break; case SVt_PVFM: total_size += sizeof(XPVFM); @@ -194,9 +198,10 @@ UV thing_size(SV *orig_thing, HV *tracking_hash) { return total_size; } - MODULE = Devel::Size PACKAGE = Devel::Size +PROTOTYPES: DISABLE + IV size(orig_thing) SV *orig_thing @@ -229,6 +234,9 @@ CODE: /* Hash to track our seen pointers */ HV *tracking_hash = newHV(); AV *pending_array = newAV(); + IV size = 0; + + IV count = 0; /* Size starts at zero */ RETVAL = 0; @@ -290,16 +298,37 @@ CODE: break; case SVt_PVGV: + /* Run through all the pieces and push the ones with bits */ + if (GvSV(thing)) { + av_push(pending_array, (SV *)GvSV(thing)); + } + if (GvFORM(thing)) { + av_push(pending_array, (SV *)GvFORM(thing)); + } + if (GvAV(thing)) { + av_push(pending_array, (SV *)GvAV(thing)); + } + if (GvHV(thing)) { + av_push(pending_array, (SV *)GvHV(thing)); + } + if (GvCV(thing)) { + av_push(pending_array, (SV *)GvCV(thing)); + } + break; default: break; } } - RETVAL += thing_size(thing, tracking_hash); + + size = thing_size(thing, tracking_hash); + RETVAL += size; + // printf("added thing of size %i, thing #%i\n", size, count++); } } /* Clean up after ourselves */ + // printf("For info, refcounts are %i, %i\n", SvREFCNT(tracking_hash), SvREFCNT(pending_array)); SvREFCNT_dec(tracking_hash); SvREFCNT_dec(pending_array); }