]> git.vpit.fr Git - perl/modules/indirect.git/blobdiff - indirect.xs
Only declare dMY_CXT when really needed
[perl/modules/indirect.git] / indirect.xs
index dde55dfa636acdfca31e461d8c1a9d9380882bd5..f7b22d35696776b29abf9045c3b31153bf649430 100644 (file)
@@ -200,6 +200,7 @@ typedef struct {
 #include "ptable.h"
 
 #define ptable_store(T, K, V) ptable_store(aTHX_ (T), (K), (V))
+#define ptable_delete(T, K)   ptable_delete(aTHX_ (T), (K))
 #define ptable_clear(T)       ptable_clear(aTHX_ (T))
 #define ptable_free(T)        ptable_free(aTHX_ (T))
 
@@ -329,7 +330,6 @@ STATIC SV *indirect_tag(pTHX_ SV *value) {
 #define indirect_tag(V) indirect_tag(aTHX_ (V))
  indirect_hint_t *h;
  SV *code = NULL;
- dMY_CXT;
 
  if (SvROK(value)) {
   value = SvRV(value);
@@ -350,10 +350,13 @@ STATIC SV *indirect_tag(pTHX_ SV *value) {
 #endif /* !I_HINT_STRUCT */
 
 #if I_THREADSAFE
- /* We only need for the key to be an unique tag for looking up the value later.
-  * Allocated memory provides convenient unique identifiers, so that's why we
-  * use the hint as the key itself. */
- ptable_hints_store(MY_CXT.tbl, h, h);
+ {
+  dMY_CXT;
+  /* We only need for the key to be an unique tag for looking up the value later
+   * Allocated memory provides convenient unique identifiers, so that's why we
+   * use the hint as the key itself. */
+  ptable_hints_store(MY_CXT.tbl, h, h);
+ }
 #endif /* I_THREADSAFE */
 
  return newSViv(PTR2IV(h));
@@ -362,14 +365,16 @@ STATIC SV *indirect_tag(pTHX_ SV *value) {
 STATIC SV *indirect_detag(pTHX_ const SV *hint) {
 #define indirect_detag(H) indirect_detag(aTHX_ (H))
  indirect_hint_t *h;
- dMY_CXT;
 
  if (!(hint && SvIOK(hint)))
   return NULL;
 
  h = INT2PTR(indirect_hint_t *, SvIVX(hint));
 #if I_THREADSAFE
- h = ptable_fetch(MY_CXT.tbl, h);
+ {
+  dMY_CXT;
+  h = ptable_fetch(MY_CXT.tbl, h);
+ }
 #endif /* I_THREADSAFE */
 
 #if I_WORKAROUND_REQUIRE_PROPAGATION
@@ -442,7 +447,7 @@ STATIC void indirect_map_delete(pTHX_ const OP *o) {
 #define indirect_map_delete(O) indirect_map_delete(aTHX_ (O))
  dMY_CXT;
 
- ptable_store(MY_CXT.map, o, NULL);
+ ptable_delete(MY_CXT.map, o);
 }
 
 /* --- Check functions ----------------------------------------------------- */
@@ -789,8 +794,6 @@ done:
 STATIC U32 indirect_initialized = 0;
 
 STATIC void indirect_teardown(pTHX_ void *root) {
- dMY_CXT;
-
  if (!indirect_initialized)
   return;
 
@@ -799,10 +802,13 @@ STATIC void indirect_teardown(pTHX_ void *root) {
   return;
 #endif
 
- ptable_free(MY_CXT.map);
+ {
+  dMY_CXT;
+  ptable_free(MY_CXT.map);
 #if I_THREADSAFE
- ptable_hints_free(MY_CXT.tbl);
 ptable_hints_free(MY_CXT.tbl);
 #endif
+ }
 
  PL_check[OP_CONST]           = MEMBER_TO_FPTR(indirect_old_ck_const);
  indirect_old_ck_const        = 0;