Now that the backreference array has no NULL entries, and is correctly
Nicholas Clark [Fri, 30 Dec 2005 15:55:05 +0000 (15:55 +0000)]
marked as AvREAL_off(), there's no reason not to use sv_dup to clone
it.

p4raw-id: //depot/perl@26541

sv.c

diff --git a/sv.c b/sv.c
index f377c59..3e3bb18 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -9076,16 +9076,9 @@ Perl_mg_dup(pTHX_ MAGIC *mg, CLONE_PARAMS* param)
            nmg->mg_obj = (SV*)re_dup((REGEXP*)mg->mg_obj, param);
        }
        else if(mg->mg_type == PERL_MAGIC_backref) {
-           const AV * const av = (AV*) mg->mg_obj;
-           SV **svp;
-           I32 i;
-           (void)SvREFCNT_inc(nmg->mg_obj = (SV*)newAV());
-           AvREAL_off((AV*)nmg->mg_obj);
-           svp = AvARRAY(av);
-           for (i = AvFILLp(av); i >= 0; i--) {
-               if (!svp[i]) continue;
-               av_push((AV*)nmg->mg_obj,sv_dup(svp[i],param));
-           }
+           /* The backref AV has its reference count deliberately bumped by
+              1.  */
+           nmg->mg_obj = SvREFCNT_inc(av_dup_inc((AV*) mg->mg_obj, param));
        }
        else if (mg->mg_type == PERL_MAGIC_symtab) {
            nmg->mg_obj = mg->mg_obj;