Wrap all accesses to the members precomp and prelen of struct regexp in
Nicholas Clark [Fri, 28 Dec 2007 21:25:50 +0000 (21:25 +0000)]
the macros RX_PRECOMP() and RX_PRELEN(). This will allow us to reduce
the regexp storage overhead by computing them at retrieve time.

p4raw-id: //depot/perl@32753

dump.c
ext/B/B.xs
ext/re/re.xs
op.c
pp_ctl.c
pp_hot.c
regcomp.c
regexec.c
regexp.h

diff --git a/dump.c b/dump.c
index 47a5285..e62da78 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -544,7 +544,7 @@ Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, const PMOP *pm)
        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 @@ Perl_do_pmop_xmldump(pTHX_ I32 level, PerlIO *file, const PMOP *pm)
     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));
index caf2265..6d5d2ab 100644 (file)
@@ -1109,7 +1109,7 @@ PMOP_precomp(o)
        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 @@ precomp(sv)
     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 @@ precomp(mg)
             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" );
index d1001c4..fa82127 100644 (file)
@@ -116,7 +116,7 @@ PPCODE:
                 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 */
diff --git a/op.c b/op.c
index bb6ac62..2185c25 100644 (file)
--- a/op.c
+++ b/op.c
@@ -7558,8 +7558,8 @@ Perl_ck_join(pTHX_ OP *o)
     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);
index 2ce3a97..5cbfd06 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -130,8 +130,8 @@ PP(pp_regcomp)
        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 @@ PP(pp_regcomp)
     }
 #endif
 
-    if (!PM_GETRE(pm)->prelen && PL_curpm)
+    if (!RX_PRELEN(PM_GETRE(pm)) && PL_curpm)
        pm = PL_curpm;
 
 
index 21582b8..5cc8087 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1261,7 +1261,7 @@ PP(pp_match)
 
 
     /* 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 @@ PP(pp_subst)
                                   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);
     }
index 90b94a3..9732086 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -4281,7 +4281,7 @@ redo_first_pass:
     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 @@ redo_first_pass:
        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 @@ redo_first_pass:
         }
 
         *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 @@ reStudy:
         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 @@ Perl_regfree_internal(pTHX_ REGEXP * const r)
        {
            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 @@ Perl_re_dup(pTHX_ const regexp *r, CLONE_PARAMS *param)
     }
 
     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)
index af7a06a..724b870 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -501,7 +501,7 @@ Perl_re_intuit_start(pTHX_ REGEXP * const prog, SV *sv, char *strpos,
 #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 @@ S_debug_start_match(pTHX_ const regexp *prog, const bool do_utf8,
             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); 
index c2ffcf3..ce3a485 100644 (file)
--- a/regexp.h
+++ b/regexp.h
@@ -353,6 +353,10 @@ and check for NULL.
                                         ? 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 */