From: Vincent Pit Date: Tue, 7 Jul 2009 19:57:04 +0000 (+0200) Subject: Factor the cloning logic in a separate function X-Git-Tag: v0.15~5 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Findirect.git;a=commitdiff_plain;h=ee6e199ac0d363cb7d67d6ea0fc695416552d959 Factor the cloning logic in a separate function --- diff --git a/indirect.xs b/indirect.xs index 01e7a33..02a13f8 100644 --- a/indirect.xs +++ b/indirect.xs @@ -183,6 +183,29 @@ START_MY_CXT #if I_THREADSAFE +STATIC SV *indirect_clone(pTHX_ SV *sv, tTHX owner) { +#define indirect_clone(S, O) indirect_clone(aTHX_ (S), (O)) + CLONE_PARAMS param; + AV *stashes = NULL; + SV *dupsv; + + if (SvTYPE(sv) == SVt_PVHV && HvNAME_get(sv)) + stashes = newAV(); + + param.stashes = stashes; + param.flags = 0; + param.proto_perl = owner; + + dupsv = sv_dup(sv, ¶m); + + if (stashes) { + av_undef(stashes); + SvREFCNT_dec(stashes); + } + + return SvREFCNT_inc(dupsv); +} + STATIC void indirect_ptable_clone(pTHX_ ptable_ent *ent, void *ud_) { my_cxt_t *ud = ud_; indirect_hint_t *h1 = ent->val; @@ -190,19 +213,8 @@ STATIC void indirect_ptable_clone(pTHX_ ptable_ent *ent, void *ud_) { *h2 = *h1; - if (ud->owner != aTHX) { - SV *val = h1->code; - CLONE_PARAMS param; - AV *stashes = (SvTYPE(val) == SVt_PVHV && HvNAME_get(val)) ? newAV() : NULL; - param.stashes = stashes; - param.flags = 0; - param.proto_perl = ud->owner; - h2->code = sv_dup(val, ¶m); - if (stashes) { - av_undef(stashes); - SvREFCNT_dec(stashes); - } - } + if (ud->owner != aTHX) + h2->code = indirect_clone(h1->code, ud->owner); ptable_hints_store(ud->tbl, ent->key, h2); SvREFCNT_inc(h2->code);