There is no need to keep a separate scalar to remember the number of
items in an array. We can just use the array.
typedef struct {
int x_GLOB_ERROR;
typedef struct {
int x_GLOB_ERROR;
HV * x_GLOB_ENTRIES;
} my_cxt_t;
HV * x_GLOB_ENTRIES;
} my_cxt_t;
SV *cxixsv = POPs;
const char *cxixpv;
STRLEN cxixlen;
SV *cxixsv = POPs;
const char *cxixpv;
STRLEN cxixlen;
SV *entriesv;
AV *entries;
U32 gimme = GIMME_V;
SV *entriesv;
AV *entries;
U32 gimme = GIMME_V;
if (SvOK(cxixsv)) cxixpv = SvPV_nomg(cxixsv, cxixlen);
else cxixpv = "_G_", cxixlen = 3;
if (SvOK(cxixsv)) cxixpv = SvPV_nomg(cxixsv, cxixlen);
else cxixpv = "_G_", cxixlen = 3;
- if (!MY_CXT.x_GLOB_ITER) MY_CXT.x_GLOB_ITER = newHV();
- itersv = *(hv_fetch(MY_CXT.x_GLOB_ITER, cxixpv, cxixlen, 1));
- if (!SvOK(itersv)) sv_setiv(itersv,0);
-
if (!MY_CXT.x_GLOB_ENTRIES) MY_CXT.x_GLOB_ENTRIES = newHV();
entriesv = *(hv_fetch(MY_CXT.x_GLOB_ENTRIES, cxixpv, cxixlen, 1));
/* if we're just beginning, do it all first */
if (!MY_CXT.x_GLOB_ENTRIES) MY_CXT.x_GLOB_ENTRIES = newHV();
entriesv = *(hv_fetch(MY_CXT.x_GLOB_ENTRIES, cxixpv, cxixlen, 1));
/* if we're just beginning, do it all first */
PUTBACK;
on_stack = globber(aTHX_ entriesv, patsv);
SPAGAIN;
PUTBACK;
on_stack = globber(aTHX_ entriesv, patsv);
SPAGAIN;
Copy(AvARRAY(entries), SP+1, AvFILLp(entries)+1, SV *);
SP += AvFILLp(entries)+1;
}
Copy(AvARRAY(entries), SP+1, AvFILLp(entries)+1, SV *);
SP += AvFILLp(entries)+1;
}
- hv_delete(MY_CXT.x_GLOB_ITER, cxixpv, cxixlen, G_DISCARD);
/* No G_DISCARD here! It will free the stack items. */
hv_delete(MY_CXT.x_GLOB_ENTRIES, cxixpv, cxixlen, 0);
}
else {
if (AvFILLp(entries) + 1) {
/* No G_DISCARD here! It will free the stack items. */
hv_delete(MY_CXT.x_GLOB_ENTRIES, cxixpv, cxixlen, 0);
}
else {
if (AvFILLp(entries) + 1) {
- sv_setiv(itersv, AvFILLp(entries) + 1);
mPUSHs(av_shift(entries));
}
else {
/* return undef for EOL */
mPUSHs(av_shift(entries));
}
else {
/* return undef for EOL */
- hv_delete(MY_CXT.x_GLOB_ITER, cxixpv, cxixlen, G_DISCARD);
hv_delete(MY_CXT.x_GLOB_ENTRIES, cxixpv, cxixlen, G_DISCARD);
PUSHs(&PL_sv_undef);
}
hv_delete(MY_CXT.x_GLOB_ENTRIES, cxixpv, cxixlen, G_DISCARD);
PUSHs(&PL_sv_undef);
}
- MY_CXT.x_GLOB_ITER = MY_CXT.x_GLOB_ENTRIES = NULL;
+ MY_CXT.x_GLOB_ENTRIES = NULL;