diff options
author | Nicholas Clark <nick@ccl4.org> | 2010-06-27 22:38:58 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2010-06-28 16:02:58 +0100 |
commit | 4c9d89c5499b414815601cb441e37d78915fb129 (patch) | |
tree | a9ebe94a060c2dd015e9ac45f79ad2cae76d5c4a /hv.c | |
parent | a50a3493249ff7bef53bf1c83fa2c08468cc78cf (diff) | |
download | perl-4c9d89c5499b414815601cb441e37d78915fb129.tar.gz |
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.
Diffstat (limited to 'hv.c')
-rw-r--r-- | hv.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -1148,19 +1148,19 @@ S_hsplit(pTHX_ HV *hv) if (!entry) /* non-existent */ continue; bep = aep+oldsize; - for (; 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. */ @@ -1314,7 +1314,7 @@ Perl_hv_ksplit(pTHX_ HV *hv, IV newmax) if (!entry) /* non-existent */ continue; - for (; entry; entry = *oentry) { + do { register I32 j = (HeHASH(entry) & newsize); if (j != i) { @@ -1322,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); } } |