From: Vincent Pit Date: Tue, 25 Oct 2011 22:32:18 +0000 (+0200) Subject: Abstract the MGWIZ creation into a new vmg_mgwiz_alloc() function X-Git-Tag: v0.47~17 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=22e4bfdeebdba03a6d923239bb75b37655a29cdb;p=perl%2Fmodules%2FVariable-Magic.git Abstract the MGWIZ creation into a new vmg_mgwiz_alloc() function --- diff --git a/Magic.xs b/Magic.xs index 062cdb3..5b3be56 100644 --- a/Magic.xs +++ b/Magic.xs @@ -459,6 +459,26 @@ typedef struct { #endif /* VMG_MULTIPLICITY */ } MGWIZ; +STATIC void vmg_op_info_init(pTHX_ unsigned int opinfo); + +STATIC MGWIZ *vmg_mgwiz_alloc(pTHX_ UV opinfo) { +#define vmg_mgwiz_alloc(O) vmg_mgwiz_alloc(aTHX_ (O)) + MGWIZ *w; + MGVTBL *t; + + Newx(w, 1, MGWIZ); + + w->uvar = 0; + w->opinfo = (U8) ((opinfo < 255) ? opinfo : 255); + if (w->opinfo) + vmg_op_info_init(aTHX_ w->opinfo); + + Newx(t, 1, MGVTBL); + w->vtbl = t; + + return w; +} + STATIC void vmg_mgwiz_free(pTHX_ MGWIZ *w) { #define vmg_mgwiz_free(W) vmg_mgwiz_free(aTHX_ (W)) if (!w) @@ -1444,10 +1464,9 @@ SV *_wizard(...) PROTOTYPE: DISABLE PREINIT: I32 i = 0; - UV opinfo; MGWIZ *w; MGVTBL *t; - SV *cb; + SV *cb, *op_info, *copy_key; CODE: dMY_CXT; @@ -1466,14 +1485,9 @@ CODE: #endif /* VMG_UVAR */ ) { croak(vmg_wrongargnum); } - Newx(t, 1, MGVTBL); - Newx(w, 1, MGWIZ); - - cb = ST(i++); - opinfo = SvOK(cb) ? SvUV(cb) : 0; - w->opinfo = (U8) ((opinfo < 255) ? opinfo : 255); - if (w->opinfo) - vmg_op_info_init(w->opinfo); + op_info = ST(i++); + w = vmg_mgwiz_alloc(SvOK(op_info) ? SvUV(op_info) : 0); + t = w->vtbl; VMG_SET_CB(ST(i++), data); @@ -1499,16 +1513,14 @@ CODE: VMG_SET_CB(ST(i++), store); VMG_SET_CB(ST(i++), exists); VMG_SET_CB(ST(i++), delete); - cb = ST(i++); + + copy_key = ST(i++); if (w->cb_fetch || w->cb_store || w->cb_exists || w->cb_delete) - w->uvar = SvTRUE(cb) ? 2 : 1; - else - w->uvar = 0; + w->uvar = SvTRUE(copy_key) ? 2 : 1; #endif /* VMG_UVAR */ #if VMG_MULTIPLICITY w->owner = aTHX; #endif /* VMG_MULTIPLICITY */ - w->vtbl = t; #if VMG_THREADSAFE ptable_store(MY_CXT.wizards, w, w); #endif /* VMG_THREADSAFE */