From: Spider Boardman Date: Mon, 30 Sep 1996 05:13:28 +0000 (-0400) Subject: Re: pre extending hash? - need speed X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=85581909df34d9ffca6c85cafeb2595c4cb89ffb;p=p5sagit%2Fp5-mst-13.2.git Re: pre extending hash? - need speed The patch below (which is relative to perl5.001l) implements "keys %hash = 50_000;" (or other integer-evaluable sizes) for pre-sizing hashes. I've only moved the patch forward from when I first did it. I'm sure the code in hv_ksplit could be improved. --- diff --git a/doop.c b/doop.c index 470ec06..0d8538c 100644 --- a/doop.c +++ b/doop.c @@ -629,8 +629,15 @@ dARGS if (op->op_type == OP_RV2HV || op->op_type == OP_PADHV) dokeys = dovalues = TRUE; - if (!hv) + if (!hv) { + if (op->op_flags & OPf_MOD) { /* lvalue */ + dTARGET; /* make sure to clear its target here */ + if (SvTYPE(TARG) == SVt_PVLV) + LvTARG(TARG) = Nullsv; + PUSHs(TARG); + } RETURN; + } (void)hv_iterinit(hv); /* always reset iterator regardless */ @@ -638,6 +645,17 @@ dARGS I32 i; dTARGET; + if (op->op_flags & OPf_MOD) { /* lvalue */ + if (SvTYPE(TARG) < SVt_PVLV) { + sv_upgrade(TARG, SVt_PVLV); + sv_magic(TARG, Nullsv, 'k', Nullch, 0); + } + LvTYPE(TARG) = 'k'; + LvTARG(TARG) = (SV*)hv; + PUSHs(TARG); + RETURN; + } + if (!SvRMAGICAL(hv) || !mg_find((SV*)hv,'P')) i = HvKEYS(hv); else {