Change 33243 by [EMAIL PROTECTED] on 2008/02/06 23:52:16

        Restore the regex positive super-linear cache, as it turns out that
        some patterns do actually benefit from it. (See
        
http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2008-01/msg01314.html )
        
        Reverses the code change of 30620 (the tests it added still pass):
        
        Integrate:
        [ 28571]
        remove regex postive super-linear cache code
        (it wasn't actually achieving anything)

Affected files ...

... //depot/maint-5.8/perl/regexec.c#102 edit

Differences ...

==== //depot/maint-5.8/perl/regexec.c#102 (text) ====
Index: perl/regexec.c
--- perl/regexec.c#101~33204~   2008-02-02 10:16:39.000000000 -0800
+++ perl/regexec.c      2008-02-06 15:52:16.000000000 -0800
@@ -1957,10 +1957,51 @@
 #define sayNO_SILENT goto do_no
 #define saySAME(x) if (x) goto yes; else goto no
 
+#define POSCACHE_SUCCESS 0     /* caching success rather than failure */
+#define POSCACHE_SEEN 1                /* we know what we're caching */
+#define POSCACHE_START 2       /* the real cache: this bit maps to pos 0 */
+
+#define CACHEsayYES STMT_START { \
+    if (cache_offset | cache_bit) { \
+       if (!(PL_reg_poscache[0] & (1<<POSCACHE_SEEN))) { \
+           PL_reg_poscache[0] |= (1<<POSCACHE_SUCCESS) | (1<<POSCACHE_SEEN); \
+           PL_reg_poscache[cache_offset] |= (1<<cache_bit); \
+       } \
+        else if (PL_reg_poscache[0] & (1<<POSCACHE_SUCCESS)) { \
+           PL_reg_poscache[cache_offset] |= (1<<cache_bit); \
+       } \
+       else { \
+           /* cache records failure, but this is success */ \
+           DEBUG_r( \
+               PerlIO_printf(Perl_debug_log, \
+                   "%*s  (remove success from failure cache)\n", \
+                   REPORT_CODE_OFF+PL_regindent*2, "") \
+           ); \
+           PL_reg_poscache[cache_offset] &= ~(1<<cache_bit); \
+       } \
+    } \
+    sayYES; \
+} STMT_END
+
 #define CACHEsayNO STMT_START { \
-    if (cache_offset | cache_bit) \
-       PL_reg_poscache[cache_offset] |= \
-           (1<<cache_bit); \
+    if (cache_offset | cache_bit) { \
+       if (!(PL_reg_poscache[0] & (1<<POSCACHE_SEEN))) { \
+           PL_reg_poscache[0] |= (1<<POSCACHE_SEEN); \
+           PL_reg_poscache[cache_offset] |= (1<<cache_bit); \
+       } \
+        else if (!(PL_reg_poscache[0] & (1<<POSCACHE_SUCCESS))) { \
+           PL_reg_poscache[cache_offset] |= (1<<cache_bit); \
+       } \
+       else { \
+           /* cache records success, but this is failure */ \
+           DEBUG_r( \
+               PerlIO_printf(Perl_debug_log, \
+                   "%*s  (remove failure from success cache)\n", \
+                   REPORT_CODE_OFF+PL_regindent*2, "") \
+           ); \
+           PL_reg_poscache[cache_offset] &= ~(1<<cache_bit); \
+       } \
+    } \
     sayNO; \
 } STMT_END
 
@@ -2949,7 +2990,7 @@
                    PL_reg_leftiter = PL_reg_maxiter;
                }
                if (PL_reg_leftiter-- == 0) {
-                   const I32 size = (PL_reg_maxiter + 7)/8;
+                   const I32 size = (PL_reg_maxiter + 7 + POSCACHE_START)/8;
                    if (PL_reg_poscache) {
                        if ((I32)PL_reg_poscache_size < size) {
                            Renew(PL_reg_poscache, size, char);
@@ -2970,7 +3011,7 @@
                if (PL_reg_leftiter < 0) {
                    cache_offset = locinput - PL_bostr;
 
-                   cache_offset = (scan->flags & 0xf) - 1
+                   cache_offset = (scan->flags & 0xf) - 1 + POSCACHE_START
                            + cache_offset * (scan->flags>>4);
                    cache_bit = cache_offset % 8;
                    cache_offset /= 8;
@@ -2980,7 +3021,12 @@
                                      "%*s  already tried at this 
position...\n",
                                      REPORT_CODE_OFF+PL_regindent*2, "")
                        );
-                       sayNO; /* cache records failure */
+                       if (PL_reg_poscache[0] & (1<<POSCACHE_SUCCESS))
+                           /* cache records success */
+                           sayYES;
+                       else
+                           /* cache records failure */
+                           sayNO_SILENT;
                    }
                }
                }
@@ -2995,7 +3041,7 @@
                    REGCP_SET(lastcp);
                    if (regmatch(cc->next)) {
                        regcpblow(cp);
-                       sayYES; /* All done. */
+                       CACHEsayYES;    /* All done. */
                    }
                    REGCP_UNWIND(lastcp);
                    regcppop();
@@ -3027,7 +3073,7 @@
                    REGCP_SET(lastcp);
                    if (regmatch(cc->scan)) {
                        regcpblow(cp);
-                       sayYES;
+                       CACHEsayYES;
                    }
                    REGCP_UNWIND(lastcp);
                    regcppop();
@@ -3045,7 +3091,7 @@
                    REGCP_SET(lastcp);
                    if (regmatch(cc->scan)) {
                        regcpblow(cp);
-                       sayYES;
+                       CACHEsayYES;
                    }
                    REGCP_UNWIND(lastcp);
                    regcppop();         /* Restore some previous $<digit>s? */
@@ -3069,7 +3115,7 @@
                if (PL_regcc)
                    ln = PL_regcc->cur;
                if (regmatch(cc->next))
-                   sayYES;
+                   CACHEsayYES;
                if (PL_regcc)
                    PL_regcc->cur = ln;
                PL_regcc = cc;
End of Patch.

Reply via email to