Change 32753 by [EMAIL PROTECTED] on 2007/12/28 21:25:50

        Wrap all accesses to the members precomp and prelen of struct regexp in
        the macros RX_PRECOMP() and RX_PRELEN(). This will allow us to reduce
        the regexp storage overhead by computing them at retrieve time.

Affected files ...

... //depot/perl/dump.c#287 edit
... //depot/perl/ext/B/B.xs#144 edit
... //depot/perl/ext/re/re.xs#52 edit
... //depot/perl/op.c#964 edit
... //depot/perl/pp_ctl.c#640 edit
... //depot/perl/pp_hot.c#538 edit
... //depot/perl/regcomp.c#622 edit
... //depot/perl/regexec.c#553 edit
... //depot/perl/regexp.h#112 edit

Differences ...

==== //depot/perl/dump.c#287 (text) ====
Index: perl/dump.c
--- perl/dump.c#286~32752~      2007-12-28 03:27:10.000000000 -0800
+++ perl/dump.c 2007-12-28 13:25:50.000000000 -0800
@@ -544,7 +544,7 @@
        ch = '/';
     if (PM_GETRE(pm))
        Perl_dump_indent(aTHX_ level, file, "PMf_PRE %c%s%c%s\n",
-            ch, PM_GETRE(pm)->precomp, ch,
+            ch, RX_PRECOMP(PM_GETRE(pm)), ch,
             (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : "");
     else
        Perl_dump_indent(aTHX_ level, file, "PMf_PRE (RUNTIME)\n");
@@ -2456,7 +2456,7 @@
     level++;
     if (PM_GETRE(pm)) {
        const regexp *const r = PM_GETRE(pm);
-       SV * const tmpsv = newSVpvn(r->precomp,r->prelen);
+       SV * const tmpsv = newSVpvn(RX_PRECOMP(r),r->prelen);
        SvUTF8_on(tmpsv);
        Perl_xmldump_indent(aTHX_ level, file, "pre=\"%s\"\n",
             SvPVX(tmpsv));

==== //depot/perl/ext/B/B.xs#144 (text) ====
Index: perl/ext/B/B.xs
--- perl/ext/B/B.xs#143~32751~  2007-12-28 01:59:06.000000000 -0800
+++ perl/ext/B/B.xs     2007-12-28 13:25:50.000000000 -0800
@@ -1109,7 +1109,7 @@
        ST(0) = sv_newmortal();
        rx = PM_GETRE(o);
        if (rx)
-           sv_setpvn(ST(0), rx->precomp, rx->prelen);
+           sv_setpvn(ST(0), RX_PRECOMP(rx), RX_PRELEN(rx));
 
 #if PERL_VERSION >= 9
 
@@ -1525,7 +1525,7 @@
     CODE:
        rx = ((struct xregexp *)SvANY(sv))->xrx_regexp;
        /* FIXME - UTF-8? And the equivalent precomp methods? */
-       RETVAL = newSVpvn( rx->precomp, rx->prelen );
+       RETVAL = newSVpvn( RX_PRECOMP(rx), RX_PRELEN(rx) );
     OUTPUT:
         RETVAL
 
@@ -1591,7 +1591,7 @@
             REGEXP* rx = (REGEXP*)mg->mg_obj;
             RETVAL = Nullsv;
             if( rx )
-                RETVAL = newSVpvn( rx->precomp, rx->prelen );
+                RETVAL = newSVpvn( RX_PRECOMP(rx), RX_PRELEN(rx) );
         }
         else {
             croak( "precomp is only meaningful on r-magic" );

==== //depot/perl/ext/re/re.xs#52 (text) ====
Index: perl/ext/re/re.xs
--- perl/ext/re/re.xs#51~32703~ 2007-12-22 08:17:01.000000000 -0800
+++ perl/ext/re/re.xs   2007-12-28 13:25:50.000000000 -0800
@@ -116,7 +116,7 @@
                 match_flags >>= 1;
             }
 
-            pattern = sv_2mortal(newSVpvn(re->precomp,re->prelen));
+            pattern = sv_2mortal(newSVpvn(RX_PRECOMP(re),RX_PRELEN(re)));
             if (re->extflags & RXf_UTF8) SvUTF8_on(pattern);
 
             /* return the pattern and the modifiers */

==== //depot/perl/op.c#964 (text) ====
Index: perl/op.c
--- perl/op.c#963~32680~        2007-12-20 13:15:57.000000000 -0800
+++ perl/op.c   2007-12-28 13:25:50.000000000 -0800
@@ -7558,8 +7558,8 @@
     if (kid && kid->op_type == OP_MATCH) {
        if (ckWARN(WARN_SYNTAX)) {
             const REGEXP *re = PM_GETRE(kPMOP);
-           const char *pmstr = re ? re->precomp : "STRING";
-           const STRLEN len = re ? re->prelen : 6;
+           const char *pmstr = re ? RX_PRECOMP(re) : "STRING";
+           const STRLEN len = re ? RX_PRELEN(re) : 6;
            Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
                        "/%.*s/ should probably be written as \"%.*s\"",
                        (int)len, pmstr, (int)len, pmstr);

==== //depot/perl/pp_ctl.c#640 (text) ====
Index: perl/pp_ctl.c
--- perl/pp_ctl.c#639~32751~    2007-12-28 01:59:06.000000000 -0800
+++ perl/pp_ctl.c       2007-12-28 13:25:50.000000000 -0800
@@ -130,8 +130,8 @@
        re = PM_GETRE(pm);
 
        /* Check against the last compiled regexp. */
-       if (!re || !re->precomp || re->prelen != (I32)len ||
-           memNE(re->precomp, t, len))
+       if (!re || !RX_PRECOMP(re) || RX_PRELEN(re) != (I32)len ||
+           memNE(RX_PRECOMP(re), t, len))
        {
            const regexp_engine *eng = re ? re->engine : NULL;
             U32 pm_flags = pm->op_pmflags & PMf_COMPILETIME;
@@ -172,7 +172,7 @@
     }
 #endif
 
-    if (!PM_GETRE(pm)->prelen && PL_curpm)
+    if (!RX_PRELEN(PM_GETRE(pm)) && PL_curpm)
        pm = PL_curpm;
 
 

==== //depot/perl/pp_hot.c#538 (text) ====
Index: perl/pp_hot.c
--- perl/pp_hot.c#537~32751~    2007-12-28 01:59:06.000000000 -0800
+++ perl/pp_hot.c       2007-12-28 13:25:50.000000000 -0800
@@ -1261,7 +1261,7 @@
 
 
     /* empty pattern special-cased to use last successful pattern if possible 
*/
-    if (!rx->prelen && PL_curpm) {
+    if (!RX_PRELEN(rx) && PL_curpm) {
        pm = PL_curpm;
        rx = PM_GETRE(pm);
     }
@@ -2091,7 +2091,7 @@
                                   position, once with zero-length,
                                   second time with non-zero. */
 
-    if (!rx->prelen && PL_curpm) {
+    if (!RX_PRELEN(rx) && PL_curpm) {
        pm = PL_curpm;
        rx = PM_GETRE(pm);
     }

==== //depot/perl/regcomp.c#622 (text) ====
Index: perl/regcomp.c
--- perl/regcomp.c#621~32751~   2007-12-28 01:59:06.000000000 -0800
+++ perl/regcomp.c      2007-12-28 13:25:50.000000000 -0800
@@ -4281,7 +4281,7 @@
     RXi_SET( r, ri );
     r->engine= RE_ENGINE_PTR;
     r->refcnt = 1;
-    r->prelen = plen;
+    RX_PRELEN(r) = plen;
     r->extflags = pm_flags;
     {
         bool has_p     = ((r->extflags & RXf_PMf_KEEPCOPY) == 
RXf_PMf_KEEPCOPY);
@@ -4290,7 +4290,7 @@
        U16 reganch = (U16)((r->extflags & RXf_PMf_STD_PMMOD) >> 12);
        const char *fptr = STD_PAT_MODS;        /*"msix"*/
        char *p;
-        r->wraplen = r->prelen + has_minus + has_p + has_runon
+        r->wraplen = RX_PRELEN(r) + has_minus + has_p + has_runon
             + (sizeof(STD_PAT_MODS) - 1)
             + (sizeof("(?:)") - 1);
 
@@ -4318,9 +4318,9 @@
         }
 
         *p++ = ':';
-        Copy(RExC_precomp, p, r->prelen, char);
-        r->precomp = p;
-        p += r->prelen;
+        Copy(RExC_precomp, p, RX_PRELEN(r), char);
+        RX_PRECOMP(r) = p;
+        p += RX_PRELEN(r);
         if (has_runon)
             *p++ = '\n';
         *p++ = ')';
@@ -4794,17 +4794,17 @@
         r->paren_names = NULL;
 
 #ifdef STUPID_PATTERN_CHECKS            
-    if (r->prelen == 0)
+    if (RX_PRELEN(r) == 0)
         r->extflags |= RXf_NULL;
-    if (r->extflags & RXf_SPLIT && r->prelen == 1 && r->precomp[0] == ' ')
+    if (r->extflags & RXf_SPLIT && RX_PRELEN(r) == 1 && RX_PRECOMP(r)[0] == ' 
')
         /* XXX: this should happen BEFORE we compile */
         r->extflags |= (RXf_SKIPWHITE|RXf_WHITE); 
-    else if (r->prelen == 3 && memEQ("\\s+", r->precomp, 3))
+    else if (RX_PRELEN(r) == 3 && memEQ("\\s+", RX_PRECOMP(r), 3))
         r->extflags |= RXf_WHITE;
-    else if (r->prelen == 1 && r->precomp[0] == '^')
+    else if (RX_PRELEN(r) == 1 && RX_PRECOMP(r)[0] == '^')
         r->extflags |= RXf_START_ONLY;
 #else
-    if (r->extflags & RXf_SPLIT && r->prelen == 1 && r->precomp[0] == ' ')
+    if (r->extflags & RXf_SPLIT && RX_PRELEN(r) == 1 && RX_PRECOMP(r)[0] == ' 
')
             /* XXX: this should happen BEFORE we compile */
             r->extflags |= (RXf_SKIPWHITE|RXf_WHITE); 
     else {
@@ -9244,7 +9244,7 @@
        {
            SV *dsv= sv_newmortal();
             RE_PV_QUOTED_DECL(s, (r->extflags & RXf_UTF8),
-                dsv, r->precomp, r->prelen, 60);
+                dsv, RX_PRECOMP(r), RX_PRELEN(r), 60);
             PerlIO_printf(Perl_debug_log,"%sFreeing REx:%s %s\n", 
                 PL_colors[4],PL_colors[5],s);
         }
@@ -9420,7 +9420,7 @@
     }
 
     ret->wrapped        = SAVEPVN(ret->wrapped, ret->wraplen+1);
-    ret->precomp        = ret->wrapped + (ret->precomp - ret->wrapped);
+    RX_PRECOMP(ret)        = ret->wrapped + (RX_PRECOMP(ret) - ret->wrapped);
     ret->paren_names    = hv_dup_inc(ret->paren_names, param);
 
     if (ret->pprivate)

==== //depot/perl/regexec.c#553 (text) ====
Index: perl/regexec.c
--- perl/regexec.c#552~32751~   2007-12-28 01:59:06.000000000 -0800
+++ perl/regexec.c      2007-12-28 13:25:50.000000000 -0800
@@ -501,7 +501,7 @@
 #ifdef QDEBUGGING      /* 7/99: reports of failure (with the older version) */
     if (end_shift < 0)
        Perl_croak(aTHX_ "panic: end_shift: %"IVdf" pattern:\n%s\n ",
-                  (IV)end_shift, prog->precomp);
+                  (IV)end_shift, RX_PRECOMP(prog));
 #endif
 
   restart:
@@ -2558,7 +2558,7 @@
             reginitcolors();    
     {
         RE_PV_QUOTED_DECL(s0, utf8_pat, PERL_DEBUG_PAD_ZERO(0), 
-            prog->precomp, prog->prelen, 60);   
+            RX_PRECOMP(prog), RX_PRELEN(prog), 60);   
         
         RE_PV_QUOTED_DECL(s1, do_utf8, PERL_DEBUG_PAD_ZERO(1), 
             start, end - start, 60); 

==== //depot/perl/regexp.h#112 (text) ====
Index: perl/regexp.h
--- perl/regexp.h#111~32237~    2007-11-07 15:23:27.000000000 -0800
+++ perl/regexp.h       2007-12-28 13:25:50.000000000 -0800
@@ -353,6 +353,10 @@
                                         ? RX_MATCH_COPIED_on(prog) \
                                         : RX_MATCH_COPIED_off(prog))
 
+/* For source compatibility. We used to store these explicitly.  */
+#define RX_PRECOMP(prog)               ((prog)->precomp)
+#define RX_PRELEN(prog)                        ((prog)->prelen)
+
 #endif /* PLUGGABLE_RE_EXTENSION */
 
 /* Stuff that needs to be included in the plugable extension goes below here */
End of Patch.

Reply via email to