/[pcre]/code/trunk/pcre_study.c
ViewVC logotype

Diff of /code/trunk/pcre_study.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 691 by ph10, Sun Sep 11 14:31:21 2011 UTC revision 697 by ph10, Mon Sep 19 12:28:24 2011 UTC
# Line 66  string of that length that matches. In U Line 66  string of that length that matches. In U
66  rather than bytes.  rather than bytes.
67    
68  Arguments:  Arguments:
69    code        pointer to start of group (the bracket)    code            pointer to start of group (the bracket)
70    startcode   pointer to start of the whole pattern    startcode       pointer to start of the whole pattern
71    options     the compiling options    options         the compiling options
72    had_accept  pointer to flag for (*ACCEPT) encountered    int             RECURSE depth
   int         RECURSE depth  
73    
74  Returns:   the minimum length  Returns:   the minimum length
75             -1 if \C was encountered             -1 if \C in UTF-8 mode or (*ACCEPT) was encountered
76             -2 internal error (missing capturing bracket)             -2 internal error (missing capturing bracket)
77             -3 internal error (opcode not listed)             -3 internal error (opcode not listed)
78  */  */
79    
80  static int  static int
81  find_minlength(const uschar *code, const uschar *startcode, int options,  find_minlength(const uschar *code, const uschar *startcode, int options,
82    BOOL *had_accept_ptr, int recurse_depth)    int recurse_depth)
83  {  {
84  int length = -1;  int length = -1;
85  BOOL utf8 = (options & PCRE_UTF8) != 0;  BOOL utf8 = (options & PCRE_UTF8) != 0;
# Line 128  for (;;) Line 127  for (;;)
127      case OP_BRAPOS:      case OP_BRAPOS:
128      case OP_SBRAPOS:      case OP_SBRAPOS:
129      case OP_ONCE:      case OP_ONCE:
130      d = find_minlength(cc, startcode, options, had_accept_ptr, recurse_depth);      d = find_minlength(cc, startcode, options, recurse_depth);
131      if (d < 0) return d;      if (d < 0) return d;
132      branchlength += d;      branchlength += d;
     if (*had_accept_ptr) return branchlength;  
133      do cc += GET(cc, 1); while (*cc == OP_ALT);      do cc += GET(cc, 1); while (*cc == OP_ALT);
134      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
135      break;      break;
136    
137      /* Reached end of a branch; if it's a ket it is the end of a nested      /* ACCEPT makes things far too complicated; we have to give up. */
     call. If it's ALT it is an alternation in a nested call. If it is END it's  
     the end of the outer call. All can be handled by the same code. If it is  
     ACCEPT, it is essentially the same as END, but we set a flag so that  
     counting stops. */  
138    
139      case OP_ACCEPT:      case OP_ACCEPT:
140      case OP_ASSERT_ACCEPT:      case OP_ASSERT_ACCEPT:
141      *had_accept_ptr = TRUE;      return -1;
142      /* Fall through */  
143        /* Reached end of a branch; if it's a ket it is the end of a nested
144        call. If it's ALT it is an alternation in a nested call. If it is END it's
145        the end of the outer call. All can be handled by the same code. If an
146        ACCEPT was previously encountered, use the length that was in force at that
147        time, and pass back the shortest ACCEPT length. */
148    
149      case OP_ALT:      case OP_ALT:
150      case OP_KET:      case OP_KET:
151      case OP_KETRMAX:      case OP_KETRMAX:
# Line 379  for (;;) Line 379  for (;;)
379          }          }
380        else        else
381          {          {
382          d = find_minlength(cs, startcode, options, had_accept_ptr,          d = find_minlength(cs, startcode, options, recurse_depth);
           recurse_depth);  
         *had_accept_ptr = FALSE;  
383          }          }
384        }        }
385      else d = 0;      else d = 0;
# Line 430  for (;;) Line 428  for (;;)
428        had_recurse = TRUE;        had_recurse = TRUE;
429      else      else
430        {        {
431        branchlength += find_minlength(cs, startcode, options, had_accept_ptr,        branchlength += find_minlength(cs, startcode, options, recurse_depth + 1);
         recurse_depth + 1);  
       *had_accept_ptr = FALSE;  
432        }        }
433      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
434      break;      break;
# Line 1228  pcre_study(const pcre *external_re, int Line 1224  pcre_study(const pcre *external_re, int
1224  {  {
1225  int min;  int min;
1226  BOOL bits_set = FALSE;  BOOL bits_set = FALSE;
 BOOL had_accept = FALSE;  
1227  uschar start_bits[32];  uschar start_bits[32];
1228  pcre_extra *extra = NULL;  pcre_extra *extra = NULL;
1229  pcre_study_data *study;  pcre_study_data *study;
# Line 1290  if ((re->options & PCRE_ANCHORED) == 0 & Line 1285  if ((re->options & PCRE_ANCHORED) == 0 &
1285    
1286  /* Find the minimum length of subject string. */  /* Find the minimum length of subject string. */
1287    
1288  switch(min = find_minlength(code, code, re->options, &had_accept, 0))  switch(min = find_minlength(code, code, re->options, 0))
1289    {    {
1290    case -2: *errorptr = "internal error: missing capturing bracket"; return NULL;    case -2: *errorptr = "internal error: missing capturing bracket"; return NULL;
1291    case -3: *errorptr = "internal error: opcode not recognized"; return NULL;    case -3: *errorptr = "internal error: opcode not recognized"; return NULL;
1292    default: break;    default: break;
1293    }    }
1294    
1295  /* If a set of starting bytes has been identified, or if the minimum length is  /* If a set of starting bytes has been identified, or if the minimum length is
1296  greater than zero, or if JIT optimization has been requested, get a pcre_extra  greater than zero, or if JIT optimization has been requested, get a pcre_extra
1297  block and a pcre_study_data block. The study data is put in the latter, which  block and a pcre_study_data block. The study data is put in the latter, which
# Line 1336  if (bits_set || min > 0 Line 1331  if (bits_set || min > 0
1331    /* Always set the minlength value in the block, because the JIT compiler    /* Always set the minlength value in the block, because the JIT compiler
1332    makes use of it. However, don't set the bit unless the length is greater than    makes use of it. However, don't set the bit unless the length is greater than
1333    zero - the interpretive pcre_exec() and pcre_dfa_exec() needn't waste time    zero - the interpretive pcre_exec() and pcre_dfa_exec() needn't waste time
1334    checking this case. */    checking the zero case. */
1335    
1336    study->minlength = min;    if (min > 0)
1337    if (min > 0) study->flags |= PCRE_STUDY_MINLEN;      {
1338        study->flags |= PCRE_STUDY_MINLEN;
1339        study->minlength = min;
1340        }
1341      else study->minlength = 0;
1342    
1343    /* If JIT support was compiled and requested, attempt the JIT compilation.    /* If JIT support was compiled and requested, attempt the JIT compilation.
1344    If no starting bytes were found, and the minimum length is zero, and JIT    If no starting bytes were found, and the minimum length is zero, and JIT

Legend:
Removed from v.691  
changed lines
  Added in v.697

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12