This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
A more efficient way to loop in ptr_table_clear
[perl5.git] / sv.c
diff --git a/sv.c b/sv.c
index f367654..d4baffc 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -9128,31 +9128,24 @@ void
 Perl_ptr_table_clear(pTHX_ PTR_TBL_t *tbl)
 {
     register PTR_TBL_ENT_t **array;
 Perl_ptr_table_clear(pTHX_ PTR_TBL_t *tbl)
 {
     register PTR_TBL_ENT_t **array;
-    register PTR_TBL_ENT_t *entry;
     UV riter = 0;
     UV riter = 0;
-    UV max;
 
     if (!tbl || !tbl->tbl_items) {
         return;
     }
 
     array = tbl->tbl_ary;
 
     if (!tbl || !tbl->tbl_items) {
         return;
     }
 
     array = tbl->tbl_ary;
-    entry = array[0];
-    max = tbl->tbl_max;
+    riter = tbl->tbl_max;
 
 
-    for (;;) {
-        if (entry) {
+    do {
+       PTR_TBL_ENT_t *entry = array[riter];
+
+       while (entry) {
             PTR_TBL_ENT_t *oentry = entry;
             entry = entry->next;
             del_pte(oentry);
         }
             PTR_TBL_ENT_t *oentry = entry;
             entry = entry->next;
             del_pte(oentry);
         }
-        if (!entry) {
-            if (++riter > max) {
-                break;
-            }
-            entry = array[riter];
-        }
-    }
+    } while (riter--);
 
     tbl->tbl_items = 0;
 }
 
     tbl->tbl_items = 0;
 }