regcomp.c: Change param to join_exact()
authorKarl Williamson <public@khwilliamson.com>
Sat, 24 Dec 2011 01:51:45 +0000 (18:51 -0700)
committerKarl Williamson <public@khwilliamson.com>
Thu, 19 Jan 2012 18:58:18 +0000 (11:58 -0700)
This changes a parameter to this function to instead of changing a running
total, return the actual value computed by the function; and it changes
the calling areas of code to compensate.

embed.fnc
proto.h
regcomp.c

index 292ccaa..b5907ba 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1899,7 +1899,7 @@ Es        |void   |regtail        |NN struct RExC_state_t *pRExC_state \
 Es     |SV *   |reg_scan_name  |NN struct RExC_state_t *pRExC_state \
                                |U32 flags
 Es     |U32    |join_exact     |NN struct RExC_state_t *pRExC_state \
-                               |NN regnode *scan|NN I32 *min|U32 flags|NULLOK regnode *val|U32 depth
+                               |NN regnode *scan|NN IV *min_change|U32 flags|NULLOK regnode *val|U32 depth
 EsRn   |char * |regwhite       |NN struct RExC_state_t *pRExC_state \
                                |NN char *p
 Es     |char * |nextchar       |NN struct RExC_state_t *pRExC_state
diff --git a/proto.h b/proto.h
index c28ec54..d410adc 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -6371,12 +6371,12 @@ PERL_STATIC_INLINE void S_invlist_trim(pTHX_ SV* const invlist)
 #define PERL_ARGS_ASSERT_INVLIST_TRIM  \
        assert(invlist)
 
-STATIC U32     S_join_exact(pTHX_ struct RExC_state_t *pRExC_state, regnode *scan, I32 *min, U32 flags, regnode *val, U32 depth)
+STATIC U32     S_join_exact(pTHX_ struct RExC_state_t *pRExC_state, regnode *scan, IV *min_change, U32 flags, regnode *val, U32 depth)
                        __attribute__nonnull__(pTHX_1)
                        __attribute__nonnull__(pTHX_2)
                        __attribute__nonnull__(pTHX_3);
 #define PERL_ARGS_ASSERT_JOIN_EXACT    \
-       assert(pRExC_state); assert(scan); assert(min)
+       assert(pRExC_state); assert(scan); assert(min_change)
 
 STATIC I32     S_make_trie(pTHX_ struct RExC_state_t *pRExC_state, regnode *startbranch, regnode *first, regnode *last, regnode *tail, U32 word_count, U32 flags, U32 depth)
                        __attribute__nonnull__(pTHX_1)
index f7bb108..11f1ca4 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -2506,14 +2506,12 @@ S_make_trie_failtable(pTHX_ RExC_state_t *pRExC_state, regnode *source,  regnode
 
 
 
-
-
-#define JOIN_EXACT(scan,min,flags) \
+#define JOIN_EXACT(scan,min_change,flags) \
     if (PL_regkind[OP(scan)] == EXACT) \
-        join_exact(pRExC_state,(scan),(min),(flags),NULL,depth+1)
+        join_exact(pRExC_state,(scan),(min_change),(flags),NULL,depth+1)
 
 STATIC U32
-S_join_exact(pTHX_ RExC_state_t *pRExC_state, regnode *scan, I32 *min, U32 flags,regnode *val, U32 depth) {
+S_join_exact(pTHX_ RExC_state_t *pRExC_state, regnode *scan, IV *min_change, U32 flags,regnode *val, U32 depth) {
     /* Merge several consecutive EXACTish nodes into one. */
     regnode *n = regnext(scan);
     U32 stringok = 1;
@@ -2595,6 +2593,8 @@ S_join_exact(pTHX_ RExC_state_t *pRExC_state, regnode *scan, I32 *min, U32 flags
 #define GREEK_SMALL_LETTER_UPSILON_WITH_DIALYTIKA_AND_TONOS    0x03B0
 #define UPSILON_D_T    GREEK_SMALL_LETTER_UPSILON_WITH_DIALYTIKA_AND_TONOS
 
+    *min_change = 0;
+
     /* Here, all the adjacent mergeable EXACTish nodes have been merged.  We
      * can now analyze for sequences of problematic code points.  (Prior to
      * this final joining, sequences could have been split over boundaries, and
@@ -2652,7 +2652,7 @@ S_join_exact(pTHX_ RExC_state_t *pRExC_state, regnode *scan, I32 *min, U32 flags
               if (((U8)t[-1] == 0xB9 && (U8)t[-2] == 0xCE) ||
                   ((U8)t[-1] == 0x85 && (U8)t[-2] == 0xCF))
 #endif
-                   *min -= 4;
+                   *min_change -= 4;
          }
     }
 
@@ -2769,10 +2769,11 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
 
   fake_study_recurse:
     while ( scan && OP(scan) != END && scan < last ){
+        IV min_change = 0;
        /* Peephole optimizer: */
        DEBUG_STUDYDATA("Peep:", data,depth);
        DEBUG_PEEP("Peep",scan,depth);
-        JOIN_EXACT(scan,&min,0);
+        JOIN_EXACT(scan,&min_change,0);
 
        /* Follow the next-chain of the current node and optimize
           away all the NOTHINGs from it.  */
@@ -3286,9 +3287,16 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
                l = utf8_length(s, s + l);
                uc = utf8_to_uvchr(s, NULL);
            }
-           min += l;
-           if (flags & SCF_DO_SUBSTR)
-               data->pos_min += l;
+           min += l + min_change;
+            if (min < 0) {
+                min = 0;
+            }
+           if (flags & SCF_DO_SUBSTR) {
+               data->pos_min += l + min_change;
+               if (data->pos_min < 0) {
+                    data->pos_min = 0;
+                }
+           }
            if (flags & SCF_DO_STCLASS_AND) {
                /* Check whether it is compatible with what we know already! */
                int compat = 1;