From: Vincent Pit Date: Fri, 3 Jul 2009 19:55:25 +0000 (+0200) Subject: Factor the cloning logic in a new lt_clone() function X-Git-Tag: v0.08~8 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLexical-Types.git;a=commitdiff_plain;h=c00bbcee86add7a0549dd9bfb9a6ddbcaa62b256 Factor the cloning logic in a new lt_clone() function --- diff --git a/Types.xs b/Types.xs index f22d034..f3ce903 100644 --- a/Types.xs +++ b/Types.xs @@ -133,6 +133,29 @@ START_MY_CXT #if LT_THREADSAFE +STATIC SV *lt_clone(pTHX_ SV *sv, tTHX owner) { +#define lt_clone(S, O) lt_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 dupsv; +} + STATIC void lt_ptable_hints_clone(pTHX_ ptable_ent *ent, void *ud_) { my_cxt_t *ud = ud_; lt_hint_t *h1 = ent->val; @@ -140,19 +163,8 @@ STATIC void lt_ptable_hints_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 = lt_clone(h1->code, ud->owner); ptable_hints_store(ud->tbl, ent->key, h2); SvREFCNT_inc(h2->code);