Change 32959 by [EMAIL PROTECTED] on 2008/01/11 17:00:59

        Pack the recycled pad offsets into an SV at PL_regex_pad[0]. This will
        use less memory than an AV.

Affected files ...

... //depot/perl/intrpvar.h#233 edit
... //depot/perl/op.c#981 edit
... //depot/perl/perl.c#847 edit

Differences ...

==== //depot/perl/intrpvar.h#233 (text) ====
Index: perl/intrpvar.h
--- perl/intrpvar.h#232~32956~  2008-01-11 07:04:51.000000000 -0800
+++ perl/intrpvar.h     2008-01-11 09:00:59.000000000 -0800
@@ -564,7 +564,8 @@
                                           regex_padav */
 PERLVAR(Iregex_padav,   AV*)           /* All regex objects, indexed via the
                                           values in op_pmoffset of pmop.
-                                          Entry 0 is an array of IVs listing
+                                          Entry 0 is an SV whose PV is a
+                                          "packed" list of IVs listing
                                           the now-free slots in the array */
 #endif
 

==== //depot/perl/op.c#981 (text) ====
Index: perl/op.c
--- perl/op.c#980~32950~        2008-01-11 04:14:04.000000000 -0800
+++ perl/op.c   2008-01-11 09:00:59.000000000 -0800
@@ -623,9 +623,11 @@
          */
 #ifdef USE_ITHREADS
        if(PL_regex_pad) {        /* We could be in destruction */
+           const IV offset = (cPMOPo)->op_pmoffset;
            ReREFCNT_dec(PM_GETRE(cPMOPo));
-            av_push((AV*) PL_regex_pad[0], newSViv((cPMOPo)->op_pmoffset));
-           PL_regex_pad[(cPMOPo)->op_pmoffset] = &PL_sv_undef;
+           PL_regex_pad[offset] = &PL_sv_undef;
+            sv_catpvn_nomg(PL_regex_pad[0], (const char *)&offset,
+                          sizeof(offset));
         }
 #else
        ReREFCNT_dec(PM_GETRE(cPMOPo));
@@ -3364,13 +3366,20 @@
 
 
 #ifdef USE_ITHREADS
-    if (av_len((AV*) PL_regex_pad[0]) > -1) {
-       SV * const repointer = av_pop((AV*)PL_regex_pad[0]);
-       const IV offset = SvIV(repointer);
+    assert(SvPOK(PL_regex_pad[0]));
+    if (SvCUR(PL_regex_pad[0])) {
+       /* Pop off the "packed" IV from the end.  */
+       SV *const repointer_list = PL_regex_pad[0];
+       const char *p = SvEND(repointer_list) - sizeof(IV);
+       const IV offset = *((IV*)p);
+
+       assert(SvCUR(repointer_list) % sizeof(IV) == 0);
+
+       SvEND_set(repointer_list, p);
+
        pmop->op_pmoffset = offset;
        /* This slot should be free, so assert this:  */
        assert(PL_regex_pad[offset] == &PL_sv_undef);
-       SvREFCNT_dec(repointer);
     } else {
        SV * const repointer = &PL_sv_undef;
        av_push(PL_regex_padav, repointer);

==== //depot/perl/perl.c#847 (text) ====
Index: perl/perl.c
--- perl/perl.c#846~32958~      2008-01-11 08:42:11.000000000 -0800
+++ perl/perl.c 2008-01-11 09:00:59.000000000 -0800
@@ -353,8 +353,9 @@
     sv_setpvn(PERL_DEBUG_PAD(1), "", 0);       /* ext/re needs these */
     sv_setpvn(PERL_DEBUG_PAD(2), "", 0);       /* even without DEBUGGING. */
 #ifdef USE_ITHREADS
-    /* First entry is an array of empty elements */
-    Perl_av_create_and_push(aTHX_ &PL_regex_padav,(SV*)newAV());
+    /* First entry is a list of empty elements. It needs to be initialised
+       else all hell breaks loose in S_find_uninit_var().  */
+    Perl_av_create_and_push(aTHX_ &PL_regex_padav, newSVpvs(""));
     PL_regex_pad = AvARRAY(PL_regex_padav);
 #endif
 #ifdef USE_REENTRANT_API
End of Patch.

Reply via email to