This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Tweak S_init_main_stash so as allocate PL_curstname as a shared string
authorNicholas Clark <nick@ccl4.org>
Fri, 30 Dec 2005 20:02:56 +0000 (20:02 +0000)
committerNicholas Clark <nick@ccl4.org>
Fri, 30 Dec 2005 20:02:56 +0000 (20:02 +0000)
scalar, and hence avoid thrashing the shared string table for "main".

p4raw-id: //depot/perl@26544

perl.c

diff --git a/perl.c b/perl.c
index b91373a..e68c064 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -3450,12 +3450,19 @@ S_init_main_stash(pTHX)
     GV *gv;
 
     PL_curstash = PL_defstash = newHV();
-    PL_curstname = newSVpvn("main",4);
+    /* We know that the string "main" will be in the global shared string
+       table, so it's a small saving to use it rather than allocate another
+       8 bytes.  */
+    PL_curstname = newSVpvn_share("main", 4, 0);
     gv = gv_fetchpv("main::",TRUE, SVt_PVHV);
+    /* If we hadn't caused another reference to "main" to be in the shared
+       string table above, then it would be worth reordering these two,
+       because otherwise all we do is delete "main" from it as a consequence
+       of the SvREFCNT_dec, only to add it again with hv_name_set */
     SvREFCNT_dec(GvHV(gv));
+    hv_name_set(PL_defstash, "main", 4, 0);
     GvHV(gv) = (HV*)SvREFCNT_inc(PL_defstash);
     SvREADONLY_on(gv);
-    hv_name_set(PL_defstash, "main", 4, 0);
     PL_incgv = gv_HVadd(gv_AVadd(gv_fetchpv("INC",TRUE, SVt_PVAV)));
     SvREFCNT_inc(PL_incgv); /* Don't allow it to be freed */
     GvMULTI_on(PL_incgv);