summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Williamson <public@khwilliamson.com>2011-12-23 18:51:45 -0700
committerKarl Williamson <public@khwilliamson.com>2011-12-23 19:16:00 -0700
commita9d15093c69d925c66bb4067fc5eb3fa74a43344 (patch)
treeeeb74df97b27bc8d9fc1286095836579e3084bbc
parent8b516b3ea741601171eac6e8de45e0340c9e0ca0 (diff)
downloadperl-a9d15093c69d925c66bb4067fc5eb3fa74a43344.tar.gz
regcomp.c: Change param to join_exact()
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.
-rw-r--r--embed.fnc2
-rw-r--r--proto.h4
-rw-r--r--regcomp.c28
3 files changed, 21 insertions, 13 deletions
diff --git a/embed.fnc b/embed.fnc
index 3b81d3fc28..db08cfabaf 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -1889,7 +1889,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 60f191aa73..c9bccb9bd6 100644
--- a/proto.h
+++ b/proto.h
@@ -6350,12 +6350,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)
diff --git a/regcomp.c b/regcomp.c
index 6917ee5520..100f73fad0 100644
--- 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;