From: Vincent Pit Date: Sun, 21 Sep 2008 22:19:16 +0000 (+0200) Subject: Shrink the context data by getting rid of the mostly useless .count member X-Git-Tag: v0.21_01~5 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=7b1220ee669f6512dea7d451111083763344094d;p=perl%2Fmodules%2FVariable-Magic.git Shrink the context data by getting rid of the mostly useless .count member --- diff --git a/Magic.xs b/Magic.xs index 9145ab3..731c084 100644 --- a/Magic.xs +++ b/Magic.xs @@ -168,10 +168,7 @@ STATIC void vmg_sv_magicuvar(pTHX_ SV *sv, const char *uf, I32 len) { #define MY_CXT_KEY __PACKAGE__ "::_guts" XS_VERSION -typedef struct { - HV *wizz; - U16 count; -} my_cxt_t; +typedef HV * my_cxt_t; START_MY_CXT @@ -192,7 +189,7 @@ STATIC U16 vmg_gensig(pTHX) { do { sig = SIG_NBR * Drand01() + SIG_MIN; - } while (hv_exists(MY_CXT.wizz, buf, sprintf(buf, "%u", sig))); + } while (hv_exists(MY_CXT, buf, sprintf(buf, "%u", sig))); return sig; } @@ -656,9 +653,7 @@ STATIC int vmg_wizard_free(pTHX_ SV *wiz, MAGIC *mg) { #endif /* VMG_MULTIPLICITY */ dMY_CXT; - if (hv_delete(MY_CXT.wizz, buf, sprintf(buf, "%u", w->sig), 0)) { - --MY_CXT.count; - } + wiz = hv_delete(MY_CXT, buf, sprintf(buf, "%u", w->sig), 0); SvFLAGS(wiz) |= SVf_BREAK; FREETMPS; @@ -748,7 +743,7 @@ STATIC U16 vmg_wizard_sig(pTHX_ SV *wiz) { dMY_CXT; - if (!hv_fetch(MY_CXT.wizz, buf, sprintf(buf, "%u", sig), 0)) + if (!hv_fetch(MY_CXT, buf, sprintf(buf, "%u", sig), 0)) sig = 0; return sig; @@ -775,7 +770,7 @@ STATIC SV *vmg_wizard_wiz(pTHX_ SV *wiz) { dMY_CXT; - return (old = hv_fetch(MY_CXT.wizz, buf, sprintf(buf, "%u", sig), 0)) + return (old = hv_fetch(MY_CXT, buf, sprintf(buf, "%u", sig), 0)) ? *old : NULL; } @@ -850,9 +845,8 @@ BOOT: { HV *stash; MY_CXT_INIT; - MY_CXT.wizz = newHV(); - hv_iterinit(MY_CXT.wizz); /* Allocate iterator */ - MY_CXT.count = 0; + MY_CXT = newHV(); + hv_iterinit(MY_CXT); /* Allocate iterator */ stash = gv_stashpv(__PACKAGE__, 1); newCONSTSUB(stash, "SIG_MIN", newSVuv(SIG_MIN)); newCONSTSUB(stash, "SIG_MAX", newSVuv(SIG_MAX)); @@ -882,11 +876,10 @@ CODE: { HE *key; dMY_CXT; - count = MY_CXT.count; hv = newHV(); hv_iterinit(hv); /* Allocate iterator */ - hv_iterinit(MY_CXT.wizz); - while (key = hv_iternext(MY_CXT.wizz)) { + hv_iterinit(MY_CXT); + while (key = hv_iternext(MY_CXT)) { STRLEN len; char *sig = HePV(key, len); SV *sv; @@ -901,8 +894,7 @@ CODE: } { MY_CXT_CLONE; - MY_CXT.wizz = hv; - MY_CXT.count = count; + MY_CXT = hv; } #endif /* VMG_THREADSAFE */ @@ -940,12 +932,12 @@ CODE: if (SvOK(svsig)) { SV **old; sig = vmg_sv2sig(svsig); - if ((old = hv_fetch(MY_CXT.wizz, buf, sprintf(buf, "%u", sig), 0))) { + if ((old = hv_fetch(MY_CXT, buf, sprintf(buf, "%u", sig), 0))) { ST(0) = sv_2mortal(newRV_inc(*old)); XSRETURN(1); } } else { - if (MY_CXT.count >= SIG_NBR) { croak(vmg_toomanysigs); } + if (HvKEYS(MY_CXT) >= SIG_NBR) { croak(vmg_toomanysigs); } sig = vmg_gensig(); } @@ -991,8 +983,7 @@ CODE: mg->mg_private = SIG_WIZ; SvREADONLY_on(sv); - hv_store(MY_CXT.wizz, buf, sprintf(buf, "%u", sig), sv, 0); - ++MY_CXT.count; + hv_store(MY_CXT, buf, sprintf(buf, "%u", sig), sv, 0); RETVAL = newRV_noinc(sv); OUTPUT: @@ -1002,7 +993,7 @@ SV *gensig() PROTOTYPE: CODE: dMY_CXT; - if (MY_CXT.count >= SIG_NBR) { croak(vmg_toomanysigs); } + if (HvKEYS(MY_CXT) >= SIG_NBR) { croak(vmg_toomanysigs); } RETVAL = newSVuv(vmg_gensig()); OUTPUT: RETVAL