From: Joshua Pritikin Date: Mon, 15 Jun 1998 10:03:37 +0000 (-0400) Subject: added patch, tweaked missed files, excised comment that doesn't really X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=800e9ae0504a9c74de77c7ab0037cc96b5df4995;p=p5sagit%2Fp5-mst-13.2.git added patch, tweaked missed files, excised comment that doesn't really belong in the sources Message-Id: Subject: [PATCH 5.004_57] tied hash slice & do_kv cleanup p4raw-id: //depot/perl@1165 --- diff --git a/ObjXSub.h b/ObjXSub.h index aa5944c..c2ef658 100644 --- a/ObjXSub.h +++ b/ObjXSub.h @@ -723,8 +723,6 @@ #define avhv_fetch pPerl->Perl_avhv_fetch #undef avhv_fetch_ent #define avhv_fetch_ent pPerl->Perl_avhv_fetch_ent -#undef avhv_iterinit -#define avhv_iterinit pPerl->Perl_avhv_iterinit #undef avhv_iternext #define avhv_iternext pPerl->Perl_avhv_iternext #undef avhv_iternextsv diff --git a/av.c b/av.c index 85bcf0c..3ced5be 100644 --- a/av.c +++ b/av.c @@ -759,13 +759,6 @@ avhv_delete_ent(AV *av, SV *keysv, I32 flags, U32 hash) return sv; } -I32 -avhv_iterinit(AV *av) -{ - HV *keys = avhv_keys(av); - return hv_iterinit(keys); -} - HE * avhv_iternext(AV *av) { diff --git a/doop.c b/doop.c index e527cde..8239c33 100644 --- a/doop.c +++ b/doop.c @@ -445,6 +445,7 @@ do_kv(ARGSproto) { djSP; HV *hv = (HV*)POPs; + HV *keys; register HE *entry; SV *tmpstr; I32 gimme = GIMME_V; @@ -465,10 +466,8 @@ do_kv(ARGSproto) RETURN; } - if (realhv) - (void)hv_iterinit(hv); /* always reset iterator regardless */ - else - (void)avhv_iterinit((AV*)hv); + keys = realhv ? hv : avhv_keys((AV*)hv); + (void)hv_iterinit(keys); /* always reset iterator regardless */ if (gimme == G_VOID) RETURN; @@ -483,33 +482,31 @@ do_kv(ARGSproto) sv_magic(TARG, Nullsv, 'k', Nullch, 0); } LvTYPE(TARG) = 'k'; - if (LvTARG(TARG) != (SV*)hv) { + if (LvTARG(TARG) != (SV*)keys) { if (LvTARG(TARG)) SvREFCNT_dec(LvTARG(TARG)); - LvTARG(TARG) = SvREFCNT_inc(hv); + LvTARG(TARG) = SvREFCNT_inc(keys); } PUSHs(TARG); RETURN; } - if (!SvRMAGICAL(hv) || !mg_find((SV*)hv,'P')) - i = HvKEYS(hv); + if (!SvRMAGICAL(keys) || !mg_find((SV*)keys,'P')) + i = HvKEYS(keys); else { i = 0; /*SUPPRESS 560*/ - while (entry = realhv ? hv_iternext(hv) : avhv_iternext((AV*)hv)) { - i++; - } + while (hv_iternext(keys)) i++; } PUSHi( i ); RETURN; } /* Guess how much room we need. hv_max may be a few too many. Oh well. */ - EXTEND(SP, HvMAX(hv) * (dokeys + dovalues)); + EXTEND(SP, HvMAX(keys) * (dokeys + dovalues)); PUTBACK; /* hv_iternext and hv_iterval might clobber stack_sp */ - while (entry = realhv ? hv_iternext(hv) : avhv_iternext((AV*)hv)) { + while (entry = hv_iternext(keys)) { SPAGAIN; if (dokeys) XPUSHs(hv_iterkeysv(entry)); /* won't clobber stack_sp */ @@ -520,8 +517,8 @@ do_kv(ARGSproto) hv_iterval(hv,entry) : avhv_iterval((AV*)hv,entry)); DEBUG_H(sv_setpvf(tmpstr, "%lu%%%d=%lu", (unsigned long)HeHASH(entry), - HvMAX(hv)+1, - (unsigned long)(HeHASH(entry) & HvMAX(hv)))); + HvMAX(keys)+1, + (unsigned long)(HeHASH(entry) & HvMAX(keys)))); SPAGAIN; XPUSHs(tmpstr); } diff --git a/embed.h b/embed.h index 9768718..352bbfb 100644 --- a/embed.h +++ b/embed.h @@ -52,7 +52,6 @@ #define avhv_exists_ent Perl_avhv_exists_ent #define avhv_fetch Perl_avhv_fetch #define avhv_fetch_ent Perl_avhv_fetch_ent -#define avhv_iterinit Perl_avhv_iterinit #define avhv_iternext Perl_avhv_iternext #define avhv_iternextsv Perl_avhv_iternextsv #define avhv_iterval Perl_avhv_iterval diff --git a/global.sym b/global.sym index 5001c3c..4a7c4b5 100644 --- a/global.sym +++ b/global.sym @@ -187,7 +187,6 @@ avhv_exists avhv_exists_ent avhv_fetch avhv_fetch_ent -avhv_iterinit avhv_iternext avhv_iternextsv avhv_iterval diff --git a/objpp.h b/objpp.h index 5a6dafb..bba19d1 100644 --- a/objpp.h +++ b/objpp.h @@ -67,8 +67,6 @@ #define avhv_delete CPerlObj::Perl_avhv_delete #undef avhv_delete_ent #define avhv_delete_ent CPerlObj::Perl_avhv_delete_ent -#undef avhv_iterinit -#define avhv_iterinit CPerlObj::Perl_avhv_iterinit #undef avhv_iternext #define avhv_iternext CPerlObj::Perl_avhv_iternext #undef avhv_iterval diff --git a/pp.c b/pp.c index aeaca4c..7d51e49 100644 --- a/pp.c +++ b/pp.c @@ -2418,7 +2418,6 @@ PP(pp_exists) PP(pp_hslice) { djSP; dMARK; dORIGMARK; - register HE *he; register HV *hv = (HV*)POPs; register I32 lval = op->op_flags & OPf_MOD; I32 realhv = (SvTYPE(hv) == SVt_PVHV); @@ -2428,18 +2427,18 @@ PP(pp_hslice) SV *keysv = *MARK; SV **svp; if (realhv) { - he = hv_fetch_ent(hv, keysv, lval, 0); + HE *he = hv_fetch_ent(hv, keysv, lval, 0); svp = he ? &HeVAL(he) : 0; } else { svp = avhv_fetch_ent((AV*)hv, keysv, lval, 0); } if (lval) { - if (!he || HeVAL(he) == &sv_undef) + if (!svp || *svp == &sv_undef) DIE(no_helem, SvPV(keysv, na)); if (op->op_private & OPpLVAL_INTRO) - save_helem(hv, keysv, &HeVAL(he)); + save_helem(hv, keysv, svp); } - *MARK = he ? HeVAL(he) : &sv_undef; + *MARK = svp ? *svp : &sv_undef; } } if (GIMME != G_ARRAY) { diff --git a/proto.h b/proto.h index d7b7762..78e6c1b 100644 --- a/proto.h +++ b/proto.h @@ -34,7 +34,6 @@ VIRTUAL bool avhv_exists _((AV *ar, char* key, U32 klen)); VIRTUAL bool avhv_exists_ent _((AV *ar, SV* keysv, U32 hash)); VIRTUAL SV** avhv_fetch _((AV *ar, char* key, U32 klen, I32 lval)); VIRTUAL SV** avhv_fetch_ent _((AV *ar, SV* keysv, I32 lval, U32 hash)); -VIRTUAL I32 avhv_iterinit _((AV *ar)); VIRTUAL HE* avhv_iternext _((AV *ar)); VIRTUAL SV * avhv_iternextsv _((AV *ar, char** key, I32* retlen)); VIRTUAL SV* avhv_iterval _((AV *ar, HE* entry)); diff --git a/t/op/avhv.t b/t/op/avhv.t index a7ce58a..84d3f27 100755 --- a/t/op/avhv.t +++ b/t/op/avhv.t @@ -17,7 +17,7 @@ sub STORESIZE { $#{$_[0]} = $_[1]+1 } package main; -print "1..5\n"; +print "1..6\n"; $sch = { 'abc' => 1, @@ -74,3 +74,8 @@ $a->[0] = \%fake; $a->{'abc'} = 'ABC'; if ($a->{'abc'} eq 'ABC') {print "ok 5\n";} else {print "not ok 5\n";} + +# hash slice +my $slice = join('', 'x',@$a{'abc','def'},'x'); +print "not " if $slice ne 'xABCx'; +print "ok 6\n";