]> git.vpit.fr Git - perl/modules/Scope-Upper.git/commitdiff
Replace the su_handler[] dispatch table by a switch
authorVincent Pit <vince@profvince.com>
Mon, 3 Aug 2015 13:15:30 +0000 (10:15 -0300)
committerVincent Pit <vince@profvince.com>
Mon, 3 Aug 2015 13:15:30 +0000 (10:15 -0300)
This lets us inline the handlers in su_pop(), which is somewhat clearer.

Upper.xs

index d34c7ffd7bc220db87bc44fc90373f19c7f9630d..c5589284fc5b3257ee0fa3da40ec3de4ef171efc 100644 (file)
--- a/Upper.xs
+++ b/Upper.xs
@@ -804,17 +804,6 @@ static void su_call(pTHX_ void *ud_) {
  SU_UD_FREE(ud);
 }
 
  SU_UD_FREE(ud);
 }
 
-static void su_reap(pTHX_ void *ud) {
-#define su_reap(U) su_reap(aTHX_ (U))
- SU_D({
-  PerlIO_printf(Perl_debug_log,
-                "%p: === reap\n%p: depth=%2d scope_ix=%2d save_ix=%2d\n",
-                 ud, ud, SU_UD_DEPTH(ud), PL_scopestack_ix, PL_savestack_ix);
- });
-
- SAVEDESTRUCTOR_X(su_call, ud);
-}
-
 /* ... Localize & localize array/hash element .............................. */
 
 typedef struct {
 /* ... Localize & localize array/hash element .............................. */
 
 typedef struct {
@@ -1026,13 +1015,7 @@ static const char *su_block_type[] = {
 # define SU_CXNAME(C) su_block_type[CxTYPE(C)]
 #endif
 
 # define SU_CXNAME(C) su_block_type[CxTYPE(C)]
 #endif
 
-static void su_uid_bump(pTHX_ void *);
-
-static void (*su_handler[])(pTHX_ void *) = {
- su_reap,
- su_localize,
- su_uid_bump
-};
+static void su_uid_bump(pTHX_ void *ud_);
 
 static void su_pop(pTHX_ void *ud) {
 #define su_pop(U) su_pop(aTHX_ (U))
 
 static void su_pop(pTHX_ void *ud) {
 #define su_pop(U) su_pop(aTHX_ (U))
@@ -1099,7 +1082,23 @@ static void su_pop(pTHX_ void *ud) {
            ud,                       depth, PL_scopestack_ix, PL_savestack_ix));
   SAVEDESTRUCTOR_X(su_pop, ud);
  } else {
            ud,                       depth, PL_scopestack_ix, PL_savestack_ix));
   SAVEDESTRUCTOR_X(su_pop, ud);
  } else {
-  su_handler[SU_UD_TYPE(ud)](aTHX_ ud);
+  switch (SU_UD_TYPE(ud)) {
+   case SU_UD_TYPE_REAP: {
+    SU_D({
+     PerlIO_printf(Perl_debug_log,
+                "%p: === reap\n%p: depth=%2d scope_ix=%2d save_ix=%2d\n",
+                 ud, ud, SU_UD_DEPTH(ud), PL_scopestack_ix, PL_savestack_ix);
+    });
+    SAVEDESTRUCTOR_X(su_call, ud);
+    break;
+   }
+   case SU_UD_TYPE_LOCALIZE:
+    su_localize(ud);
+    break;
+   case SU_UD_TYPE_UID:
+    su_uid_bump(aTHX_ ud);
+    break;
+  }
  }
 
  SU_D(PerlIO_printf(Perl_debug_log,
  }
 
  SU_D(PerlIO_printf(Perl_debug_log,