In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/4c9d89c5499b414815601cb441e37d78915fb129?hp=2d635dbfcbbec8b4f85ef7e32e26b482c38d4ee8>
- Log ----------------------------------------------------------------- commit 4c9d89c5499b414815601cb441e37d78915fb129 Author: Nicholas Clark <[email protected]> Date: Sun Jun 27 22:38:58 2010 +0100 Refactor loops in S_hsplit(), Perl_hv_ksplit() and Perl_ptr_table_split(). Change from for() to do ... while() loops. Move variable initialisation to variable declaration. Avoid needing to use the comma operator to allow multiple statements in for(). Avoid using a continue statement where it isn't actually needed to change flow control. Avoid relying on the optimiser to know that the for loop conditional doesn't need testing on the first pass. A current gcc's optimiser produces identical code despite these changes. However, for the reasons given I consider the code to be much clearer. M hv.c M sv.c commit a50a3493249ff7bef53bf1c83fa2c08468cc78cf Author: Nicholas Clark <[email protected]> Date: Sun Jun 27 22:19:37 2010 +0100 Move variable declarations inwards in S_hsplit() and Perl_hv_ksplit(). M hv.c ----------------------------------------------------------------------- Summary of changes: hv.c | 25 +++++++++++++------------ sv.c | 12 +++++++----- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/hv.c b/hv.c index 08ca8d0..880a46d 100644 --- a/hv.c +++ b/hv.c @@ -1085,7 +1085,6 @@ S_hsplit(pTHX_ HV *hv) register I32 i; char *a = (char*) HvARRAY(hv); register HE **aep; - register HE **oentry; int longest_chain = 0; int was_shared; @@ -1142,25 +1141,26 @@ S_hsplit(pTHX_ HV *hv) for (i=0; i<oldsize; i++,aep++) { int left_length = 0; int right_length = 0; - register HE *entry; + HE **oentry = aep; + HE *entry = *aep; register HE **bep; - if (!*aep) /* non-existent */ + if (!entry) /* non-existent */ continue; bep = aep+oldsize; - for (oentry = aep, entry = *aep; entry; entry = *oentry) { + do { if ((HeHASH(entry) & newsize) != (U32)i) { *oentry = HeNEXT(entry); HeNEXT(entry) = *bep; *bep = entry; right_length++; - continue; } else { oentry = &HeNEXT(entry); left_length++; } - } + entry = *oentry; + } while (entry); /* I think we don't actually need to keep track of the longest length, merely flag if anything is too long. But for the moment while developing this code I'll track it. */ @@ -1250,8 +1250,6 @@ Perl_hv_ksplit(pTHX_ HV *hv, IV newmax) register I32 i; register char *a; register HE **aep; - register HE *entry; - register HE **oentry; PERL_ARGS_ASSERT_HV_KSPLIT; @@ -1311,9 +1309,12 @@ Perl_hv_ksplit(pTHX_ HV *hv, IV newmax) aep = (HE**)a; for (i=0; i<oldsize; i++,aep++) { - if (!*aep) /* non-existent */ + HE **oentry = aep; + HE *entry = *aep; + + if (!entry) /* non-existent */ continue; - for (oentry = aep, entry = *aep; entry; entry = *oentry) { + do { register I32 j = (HeHASH(entry) & newsize); if (j != i) { @@ -1321,11 +1322,11 @@ Perl_hv_ksplit(pTHX_ HV *hv, IV newmax) *oentry = HeNEXT(entry); HeNEXT(entry) = aep[j]; aep[j] = entry; - continue; } else oentry = &HeNEXT(entry); - } + entry = *oentry; + } while (entry); } } diff --git a/sv.c b/sv.c index cc8fe49..9a4a082 100644 --- a/sv.c +++ b/sv.c @@ -10875,20 +10875,22 @@ Perl_ptr_table_split(pTHX_ PTR_TBL_t *const tbl) tbl->tbl_max = --newsize; tbl->tbl_ary = ary; for (i=0; i < oldsize; i++, ary++) { - PTR_TBL_ENT_t **curentp, **entp, *ent; - if (!*ary) + PTR_TBL_ENT_t **entp = ary; + PTR_TBL_ENT_t *ent = *ary; + PTR_TBL_ENT_t **curentp; + if (!ent) continue; curentp = ary + oldsize; - for (entp = ary, ent = *ary; ent; ent = *entp) { + do { if ((newsize & PTR_TABLE_HASH(ent->oldval)) != i) { *entp = ent->next; ent->next = *curentp; *curentp = ent; - continue; } else entp = &ent->next; - } + ent = *entp; + } while (ent); } } -- Perl5 Master Repository
