From: Vincent Pit Date: Fri, 29 May 2009 09:52:20 +0000 (+0200) Subject: Don't actually create an entry when storing NULL in the ptable X-Git-Tag: v0.14~3 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=99241a0dc1d2077b248099868a7692967469b00d;p=perl%2Fmodules%2Findirect.git Don't actually create an entry when storing NULL in the ptable This is actually unneeded because ptable_fetch() returns NULL when it can't find the entry. This way we can remove the short-lived ptable_delete(). --- diff --git a/indirect.xs b/indirect.xs index f318932..12256c3 100644 --- a/indirect.xs +++ b/indirect.xs @@ -163,7 +163,6 @@ 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)) @@ -392,7 +391,7 @@ STATIC void indirect_map_delete(pTHX_ const OP *o) { #define indirect_map_delete(O) indirect_map_delete(aTHX_ (O)) dMY_CXT; - ptable_delete(MY_CXT.map, o); + ptable_store(MY_CXT.map, o, NULL); } /* --- Check functions ----------------------------------------------------- */ diff --git a/ptable.h b/ptable.h index ba275ba..f3d2712 100644 --- a/ptable.h +++ b/ptable.h @@ -117,16 +117,6 @@ STATIC void *ptable_fetch(const ptable * const t, const void * const key) { } #endif /* !ptable_fetch */ -STATIC void PTABLE_PREFIX(_delete)(pPTBL_ const ptable * const t, const void * const key) { - ptable_ent *const ent = ptable_find(t, key); - - if (ent) { - void *val = ent->val; - PTABLE_VAL_FREE(val); - ent->val = NULL; - } -} - #ifndef ptable_split STATIC void ptable_split(pPTBLMS_ ptable * const t) { #define ptable_split(T) ptable_split(aPTBLMS_ (T)) @@ -165,7 +155,7 @@ STATIC void PTABLE_PREFIX(_store)(pPTBL_ ptable * const t, const void * const ke void *oldval = ent->val; PTABLE_VAL_FREE(oldval); ent->val = val; - } else { + } else if (val) { const UV i = PTABLE_HASH(key) & t->max; ent = PerlMemShared_malloc(sizeof *ent); ent->key = key;