From: Nicholas Clark Date: Thu, 14 Apr 2011 17:39:48 +0000 (+0100) Subject: Create free_tracking() to de-duplicate the code to free the tracking structure. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e9716740608f4872c590a9120187210c04c2778c;hp=1c566e6ab8500795b29fd593e67aa8d6f1aa9b0b;p=p5sagit%2FDevel-Size.git Create free_tracking() to de-duplicate the code to free the tracking structure. --- diff --git a/Size.xs b/Size.xs index 45a23a4..69cd815 100644 --- a/Size.xs +++ b/Size.xs @@ -86,6 +86,18 @@ check_new(TRACKING *tv, const void *const p) { return TRUE; } +static void +free_tracking(TRACKING *tv) +{ + int i; + /* Clean up after ourselves */ + for( i = 0; i < TRACKING_SLOTS; ++i ) { + if( (*tv)[ i ] ) + Safefree( (*tv)[ i ] ); + } + Safefree( tv ); +} + UV thing_size(const SV *const, TRACKING *); typedef enum { OPc_NULL, /* 0 */ @@ -729,7 +741,6 @@ size(orig_thing) SV *orig_thing CODE: { - int i; SV *thing = orig_thing; /* Hash to track our seen pointers */ //HV *tracking_hash = newHV(); @@ -762,13 +773,7 @@ CODE: #endif RETVAL = thing_size(thing, tv); - /* Clean up after ourselves */ - //SvREFCNT_dec(tracking_hash); - for( i = 0; i < TRACKING_SLOTS; ++i ) { - if( (*tv)[ i ] ) - Safefree( (*tv)[ i ] ); - } - Safefree( tv ); + free_tracking(tv); } OUTPUT: RETVAL @@ -779,7 +784,6 @@ total_size(orig_thing) SV *orig_thing CODE: { - int i; SV *thing = orig_thing; /* Hash to track our seen pointers */ //HV *tracking_hash; @@ -922,14 +926,8 @@ CODE: #endif } } /* end while */ - - /* Clean up after ourselves */ - //SvREFCNT_dec(tracking_hash); - for( i = 0; i < TRACKING_SLOTS; ++i ) { - if( (*tv)[ i ] ) - Safefree( (*tv)[ i ] ); - } - Safefree( tv ); + + free_tracking(tv); SvREFCNT_dec(pending_array); } OUTPUT: