This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
in CLONEf_JOIN_IN, cache found stashes
authorDavid Mitchell <davem@iabyn.com>
Mon, 5 Jul 2010 21:25:12 +0000 (22:25 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 14 Jul 2010 22:06:17 +0000 (23:06 +0100)
When joining a thread, we skip cloning a stash if a stash of the same
name already exists in the parent thread. Add it to PL_ptr_table too, so
we don't have to repeat the expensive name comparison each time

sv.c

diff --git a/sv.c b/sv.c
index 88da54b..13a1390 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -11071,9 +11071,12 @@ S_sv_dup_common(pTHX_ const SV *const sstr, CLONE_PARAMS *const param)
            something that is bad **/
        if (SvTYPE(sstr) == SVt_PVHV) {
            const HEK * const hvname = HvNAME_HEK(sstr);
-           if (hvname)
+           if (hvname) {
                /** don't clone stashes if they already exist **/
-               return MUTABLE_SV(gv_stashpvn(HEK_KEY(hvname), HEK_LEN(hvname), 0));
+               dstr = MUTABLE_SV(gv_stashpvn(HEK_KEY(hvname), HEK_LEN(hvname), 0));
+               ptr_table_store(PL_ptr_table, sstr, dstr);
+               return dstr;
+           }
         }
     }