summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2010-06-27 22:38:58 +0100
committerNicholas Clark <nick@ccl4.org>2010-06-28 16:02:58 +0100
commit4c9d89c5499b414815601cb441e37d78915fb129 (patch)
treea9ebe94a060c2dd015e9ac45f79ad2cae76d5c4a /sv.c
parenta50a3493249ff7bef53bf1c83fa2c08468cc78cf (diff)
downloadperl-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 'sv.c')
-rw-r--r--sv.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/sv.c b/sv.c
index cc8fe49e3b..9a4a082309 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);
}
}