/[pcre]/code/tags/pcre-8.37/pcre_jit_compile.c
ViewVC logotype

Diff of /code/tags/pcre-8.37/pcre_jit_compile.c

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

revision 1424 by zherczeg, Tue Dec 31 11:22:31 2013 UTC revision 1476 by zherczeg, Mon Apr 28 06:49:36 2014 UTC
# Line 179  typedef struct jit_arguments { Line 179  typedef struct jit_arguments {
179    
180  typedef struct executable_functions {  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182      sljit_uw *read_only_data[JIT_NUMBER_OF_COMPILE_MODES];
183      sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
184    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
185    void *userdata;    void *userdata;
186    pcre_uint32 top_bracket;    pcre_uint32 top_bracket;
187    pcre_uint32 limit_match;    pcre_uint32 limit_match;
   sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];  
188  } executable_functions;  } executable_functions;
189    
190  typedef struct jump_list {  typedef struct jump_list {
# Line 197  typedef struct stub_list { Line 198  typedef struct stub_list {
198    struct stub_list *next;    struct stub_list *next;
199  } stub_list;  } stub_list;
200    
201    typedef struct label_addr_list {
202      struct sljit_label *label;
203      sljit_uw *update_addr;
204      struct label_addr_list *next;
205    } label_addr_list;
206    
207  enum frame_types {  enum frame_types {
208    no_frame = -1,    no_frame = -1,
209    no_stack = -2    no_stack = -2
# Line 315  typedef struct compiler_common { Line 322  typedef struct compiler_common {
322    pcre_uchar *start;    pcre_uchar *start;
323    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
324    sljit_si *private_data_ptrs;    sljit_si *private_data_ptrs;
325      /* This read-only data is available during runtime. */
326      sljit_uw *read_only_data;
327      /* The total size of the read-only data. */
328      sljit_uw read_only_data_size;
329      /* The next free entry of the read_only_data. */
330      sljit_uw *read_only_data_ptr;
331    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
332    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
333    /* Tells whether the starting offset is a target of then. */    /* Tells whether the starting offset is a target of then. */
# Line 349  typedef struct compiler_common { Line 362  typedef struct compiler_common {
362    sljit_sw lcc;    sljit_sw lcc;
363    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
364    int mode;    int mode;
365      /* TRUE, when minlength is greater than 0. */
366      BOOL might_be_empty;
367    /* \K is found in the pattern. */    /* \K is found in the pattern. */
368    BOOL has_set_som;    BOOL has_set_som;
369    /* (*SKIP:arg) is found in the pattern. */    /* (*SKIP:arg) is found in the pattern. */
# Line 364  typedef struct compiler_common { Line 379  typedef struct compiler_common {
379    /* Newline control. */    /* Newline control. */
380    int nltype;    int nltype;
381    pcre_uint32 nlmax;    pcre_uint32 nlmax;
382      pcre_uint32 nlmin;
383    int newline;    int newline;
384    int bsr_nltype;    int bsr_nltype;
385    pcre_uint32 bsr_nlmax;    pcre_uint32 bsr_nlmax;
386      pcre_uint32 bsr_nlmin;
387    /* Dollar endonly. */    /* Dollar endonly. */
388    int endonly;    int endonly;
389    /* Tables. */    /* Tables. */
# Line 381  typedef struct compiler_common { Line 398  typedef struct compiler_common {
398    struct sljit_label *quit_label;    struct sljit_label *quit_label;
399    struct sljit_label *forced_quit_label;    struct sljit_label *forced_quit_label;
400    struct sljit_label *accept_label;    struct sljit_label *accept_label;
401      struct sljit_label *ff_newline_shortcut;
402    stub_list *stubs;    stub_list *stubs;
403      label_addr_list *label_addrs;
404    recurse_entry *entries;    recurse_entry *entries;
405    recurse_entry *currententry;    recurse_entry *currententry;
406    jump_list *partialmatch;    jump_list *partialmatch;
# Line 524  the start pointers when the end of the c Line 543  the start pointers when the end of the c
543  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
544    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
545    
546  #define READ_CHAR_ANY 0x7fffffff  #define READ_CHAR_MAX 0x7fffffff
547    
548  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
549  {  {
# Line 535  cc += 1 + LINK_SIZE; Line 554  cc += 1 + LINK_SIZE;
554  return cc;  return cc;
555  }  }
556    
557    static int no_alternatives(pcre_uchar* cc)
558    {
559    int count = 0;
560    SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
561    do
562      {
563      cc += GET(cc, 1);
564      count++;
565      }
566    while (*cc == OP_ALT);
567    SLJIT_ASSERT(*cc >= OP_KET && *cc <= OP_KETRPOS);
568    return count;
569    }
570    
571  static int ones_in_half_byte[16] = {  static int ones_in_half_byte[16] = {
572    /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,    /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
573    /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4    /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
# Line 759  while (cc < ccend) Line 792  while (cc < ccend)
792      {      {
793      case OP_SET_SOM:      case OP_SET_SOM:
794      common->has_set_som = TRUE;      common->has_set_som = TRUE;
795        common->might_be_empty = TRUE;
796      cc += 1;      cc += 1;
797      break;      break;
798    
# Line 768  while (cc < ccend) Line 802  while (cc < ccend)
802      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
803      break;      break;
804    
805        case OP_BRA:
806        case OP_CBRA:
807        case OP_SBRA:
808        case OP_SCBRA:
809        count = no_alternatives(cc);
810        if (count > 4)
811          common->read_only_data_size += count * sizeof(sljit_uw);
812        cc += 1 + LINK_SIZE + (*cc == OP_CBRA || *cc == OP_SCBRA ? IMM2_SIZE : 0);
813        break;
814    
815      case OP_CBRAPOS:      case OP_CBRAPOS:
816      case OP_SCBRAPOS:      case OP_SCBRAPOS:
817      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
# Line 2026  while (list_item) Line 2070  while (list_item)
2070  common->stubs = NULL;  common->stubs = NULL;
2071  }  }
2072    
2073    static void add_label_addr(compiler_common *common, sljit_uw *update_addr)
2074    {
2075    DEFINE_COMPILER;
2076    label_addr_list *label_addr;
2077    
2078    label_addr = sljit_alloc_memory(compiler, sizeof(label_addr_list));
2079    if (label_addr == NULL)
2080      return;
2081    label_addr->label = LABEL();
2082    label_addr->update_addr = update_addr;
2083    label_addr->next = common->label_addrs;
2084    common->label_addrs = label_addr;
2085    }
2086    
2087  static SLJIT_INLINE void count_match(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2088  {  {
2089  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2464  else Line 2522  else
2522  JUMPHERE(jump);  JUMPHERE(jump);
2523  }  }
2524    
2525  static void peek_char(compiler_common *common)  static void peek_char(compiler_common *common, pcre_uint32 max)
2526  {  {
2527  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2528  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
# Line 2473  DEFINE_COMPILER; Line 2531  DEFINE_COMPILER;
2531  struct sljit_jump *jump;  struct sljit_jump *jump;
2532  #endif  #endif
2533    
2534    SLJIT_UNUSED_ARG(max);
2535    
2536  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2537  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2538  if (common->utf)  if (common->utf)
2539    {    {
2540      if (max < 128) return;
2541    
2542    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2543    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2544    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
# Line 2488  if (common->utf) Line 2550  if (common->utf)
2550  #if defined SUPPORT_UTF && defined COMPILE_PCRE16  #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2551  if (common->utf)  if (common->utf)
2552    {    {
2553      if (max < 0xd800) return;
2554    
2555    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2556    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2557    /* TMP2 contains the high surrogate. */    /* TMP2 contains the high surrogate. */
# Line 2503  if (common->utf) Line 2567  if (common->utf)
2567    
2568  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2569    
2570  static BOOL is_char7_bitset(const pcre_uint8* bitset, BOOL nclass)  static BOOL is_char7_bitset(const pcre_uint8 *bitset, BOOL nclass)
2571  {  {
2572  /* Tells whether the character codes below 128 are enough  /* Tells whether the character codes below 128 are enough
2573  to determine a match. */  to determine a match. */
# Line 2546  if (full_read) Line 2610  if (full_read)
2610    
2611  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2612    
2613  static void read_char_max(compiler_common *common, pcre_uint32 max, BOOL full_read)  static void read_char_range(compiler_common *common, pcre_uint32 min, pcre_uint32 max, BOOL update_str_ptr)
2614  {  {
2615  /* Reads the precise value of a character into TMP1, if the character is  /* Reads the precise value of a character into TMP1, if the character is
2616  less than or equal to max. Otherwise it returns with a value greater than max.  between min and max (c >= min && c <= max). Otherwise it returns with a value
2617  Does not check STR_END. The full_read argument tells whether characters above  outside the range. Does not check STR_END. */
 max are accepted or not. */  
2618  DEFINE_COMPILER;  DEFINE_COMPILER;
2619  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2620  struct sljit_jump *jump;  struct sljit_jump *jump;
2621  #endif  #endif
2622    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2623    struct sljit_jump *jump2;
2624    #endif
2625    
2626  SLJIT_UNUSED_ARG(full_read);  SLJIT_UNUSED_ARG(update_str_ptr);
2627    SLJIT_UNUSED_ARG(min);
2628  SLJIT_UNUSED_ARG(max);  SLJIT_UNUSED_ARG(max);
2629    SLJIT_ASSERT(min <= max);
2630    
2631  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2632  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2633    
2634  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2635  if (common->utf)  if (common->utf)
2636    {    {
2637    if (max < 128 && !full_read)    if (max < 128 && !update_str_ptr) return;
     return;  
2638    
2639    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2640    if (max >= 0x800)    if (min >= 0x10000)
2641        {
2642        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf0);
2643        if (update_str_ptr)
2644          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2645        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2646        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x7);
2647        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2648        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2649        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2650        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2651        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2652        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2653        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2654        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2655        if (!update_str_ptr)
2656          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2657        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2658        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2659        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2660        JUMPHERE(jump2);
2661        if (update_str_ptr)
2662          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2663        }
2664      else if (min >= 0x800 && max <= 0xffff)
2665        {
2666        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xe0);
2667        if (update_str_ptr)
2668          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2669        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2670        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xf);
2671        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2672        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2673        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2674        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2675        if (!update_str_ptr)
2676          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2677        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2678        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2679        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2680        JUMPHERE(jump2);
2681        if (update_str_ptr)
2682          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2683        }
2684      else if (max >= 0x800)
2685      add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));      add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2686    else if (max < 128)    else if (max < 128)
2687      {      {
# Line 2580  if (common->utf) Line 2691  if (common->utf)
2691    else    else
2692      {      {
2693      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2694      if (!full_read)      if (!update_str_ptr)
2695        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2696      else      else
2697        OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);        OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
# Line 2588  if (common->utf) Line 2699  if (common->utf)
2699      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2700      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2701      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2702      if (full_read)      if (update_str_ptr)
2703        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2704      }      }
2705    JUMPHERE(jump);    JUMPHERE(jump);
# Line 2613  if (common->utf) Line 2724  if (common->utf)
2724      return;      return;
2725      }      }
2726    
2727    if (max < 0xd800 && !full_read)    if (max < 0xd800 && !update_str_ptr) return;
     return;  
2728    
2729    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2730    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2731    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2732    if (full_read)    if (update_str_ptr)
2733      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2734    if (max >= 0xd800)    if (max >= 0xd800)
2735      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
# Line 2630  if (common->utf) Line 2740  if (common->utf)
2740    
2741  static SLJIT_INLINE void read_char(compiler_common *common)  static SLJIT_INLINE void read_char(compiler_common *common)
2742  {  {
2743  read_char_max(common, READ_CHAR_ANY, TRUE);  read_char_range(common, 0, READ_CHAR_MAX, TRUE);
2744  }  }
2745    
2746  static void read_char8_type(compiler_common *common, BOOL full_read)  static void read_char8_type(compiler_common *common, BOOL update_str_ptr)
2747  {  {
2748  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END.  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */
 The full_read argument tells whether characters above max are accepted or not. */  
2749  DEFINE_COMPILER;  DEFINE_COMPILER;
2750  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2751  struct sljit_jump *jump;  struct sljit_jump *jump;
# Line 2645  struct sljit_jump *jump; Line 2754  struct sljit_jump *jump;
2754  struct sljit_jump *jump2;  struct sljit_jump *jump2;
2755  #endif  #endif
2756    
2757  SLJIT_UNUSED_ARG(full_read);  SLJIT_UNUSED_ARG(update_str_ptr);
2758    
2759  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2760  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
# Line 2657  if (common->utf) Line 2766  if (common->utf)
2766    it is needed in most cases. */    it is needed in most cases. */
2767    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2768    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2769    if (!full_read)    if (!update_str_ptr)
2770      {      {
2771      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2772      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
# Line 2688  JUMPHERE(jump); Line 2797  JUMPHERE(jump);
2797  #endif  #endif
2798    
2799  #if defined SUPPORT_UTF && defined COMPILE_PCRE16  #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2800  if (common->utf && full_read)  if (common->utf && update_str_ptr)
2801    {    {
2802    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2803    OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
# Line 2964  if (firstline) Line 3073  if (firstline)
3073      mainloop = LABEL();      mainloop = LABEL();
3074      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
3075      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
3076      read_char_max(common, common->nlmax, TRUE);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
3077      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
3078      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
3079      JUMPHERE(end);      JUMPHERE(end);
# Line 3040  if (newlinecheck) Line 3149  if (newlinecheck)
3149  return mainloop;  return mainloop;
3150  }  }
3151    
3152  static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, int max_chars)  #define MAX_N_CHARS 16
3153    #define MAX_N_BYTES 8
3154    
3155    static SLJIT_INLINE void add_prefix_byte(pcre_uint8 byte, pcre_uint8 *bytes)
3156    {
3157    pcre_uint8 len = bytes[0];
3158    int i;
3159    
3160    if (len == 255)
3161      return;
3162    
3163    if (len == 0)
3164      {
3165      bytes[0] = 1;
3166      bytes[1] = byte;
3167      return;
3168      }
3169    
3170    for (i = len; i > 0; i--)
3171      if (bytes[i] == byte)
3172        return;
3173    
3174    if (len >= MAX_N_BYTES - 1)
3175      {
3176      bytes[0] = 255;
3177      return;
3178      }
3179    
3180    len++;
3181    bytes[len] = byte;
3182    bytes[0] = len;
3183    }
3184    
3185    static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, pcre_uint8 *bytes, int max_chars)
3186  {  {
3187  /* Recursive function, which scans prefix literals. */  /* Recursive function, which scans prefix literals. */
3188    BOOL last, any, caseless;
3189  int len, repeat, len_save, consumed = 0;  int len, repeat, len_save, consumed = 0;
3190  pcre_uint32 caseless, chr, mask;  pcre_uint32 chr, mask;
3191  pcre_uchar *alternative, *cc_save;  pcre_uchar *alternative, *cc_save, *oc;
3192  BOOL last, any;  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3193    pcre_uchar othercase[8];
3194    #elif defined SUPPORT_UTF && defined COMPILE_PCRE16
3195    pcre_uchar othercase[2];
3196    #else
3197    pcre_uchar othercase[1];
3198    #endif
3199    
3200  repeat = 1;  repeat = 1;
3201  while (TRUE)  while (TRUE)
3202    {    {
3203    last = TRUE;    last = TRUE;
3204    any = FALSE;    any = FALSE;
3205    caseless = 0;    caseless = FALSE;
3206    switch (*cc)    switch (*cc)
3207      {      {
3208      case OP_CHARI:      case OP_CHARI:
3209      caseless = 1;      caseless = TRUE;
3210      case OP_CHAR:      case OP_CHAR:
3211      last = FALSE;      last = FALSE;
3212      cc++;      cc++;
# Line 3078  while (TRUE) Line 3227  while (TRUE)
3227      cc++;      cc++;
3228      continue;      continue;
3229    
3230        case OP_ASSERT:
3231        case OP_ASSERT_NOT:
3232        case OP_ASSERTBACK:
3233        case OP_ASSERTBACK_NOT:
3234        cc = bracketend(cc);
3235        continue;
3236    
3237        case OP_PLUSI:
3238        case OP_MINPLUSI:
3239        case OP_POSPLUSI:
3240        caseless = TRUE;
3241      case OP_PLUS:      case OP_PLUS:
3242      case OP_MINPLUS:      case OP_MINPLUS:
3243      case OP_POSPLUS:      case OP_POSPLUS:
# Line 3085  while (TRUE) Line 3245  while (TRUE)
3245      break;      break;
3246    
3247      case OP_EXACTI:      case OP_EXACTI:
3248      caseless = 1;      caseless = TRUE;
3249      case OP_EXACT:      case OP_EXACT:
3250      repeat = GET2(cc, 1);      repeat = GET2(cc, 1);
3251      last = FALSE;      last = FALSE;
3252      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3253      break;      break;
3254    
3255      case OP_PLUSI:      case OP_QUERYI:
3256      case OP_MINPLUSI:      case OP_MINQUERYI:
3257      case OP_POSPLUSI:      case OP_POSQUERYI:
3258      caseless = 1;      caseless = TRUE;
3259        case OP_QUERY:
3260        case OP_MINQUERY:
3261        case OP_POSQUERY:
3262        len = 1;
3263      cc++;      cc++;
3264    #ifdef SUPPORT_UTF
3265        if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3266    #endif
3267        max_chars = scan_prefix(common, cc + len, chars, bytes, max_chars);
3268        if (max_chars == 0)
3269          return consumed;
3270        last = FALSE;
3271      break;      break;
3272    
3273      case OP_KET:      case OP_KET:
# Line 3116  while (TRUE) Line 3287  while (TRUE)
3287      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
3288      while (*alternative == OP_ALT)      while (*alternative == OP_ALT)
3289        {        {
3290        max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);        max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, bytes, max_chars);
3291        if (max_chars == 0)        if (max_chars == 0)
3292          return consumed;          return consumed;
3293        alternative += GET(alternative, 1);        alternative += GET(alternative, 1);
# Line 3128  while (TRUE) Line 3299  while (TRUE)
3299      continue;      continue;
3300    
3301      case OP_CLASS:      case OP_CLASS:
3302    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3303        if (common->utf && !is_char7_bitset((const pcre_uint8 *)(cc + 1), FALSE)) return consumed;
3304    #endif
3305        any = TRUE;
3306        cc += 1 + 32 / sizeof(pcre_uchar);
3307        break;
3308    
3309      case OP_NCLASS:      case OP_NCLASS:
3310    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3311        if (common->utf) return consumed;
3312    #endif
3313      any = TRUE;      any = TRUE;
3314      cc += 1 + 32 / sizeof(pcre_uchar);      cc += 1 + 32 / sizeof(pcre_uchar);
3315      break;      break;
3316    
3317  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3318      case OP_XCLASS:      case OP_XCLASS:
3319    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3320        if (common->utf) return consumed;
3321    #endif
3322      any = TRUE;      any = TRUE;
3323      cc += GET(cc, 1);      cc += GET(cc, 1);
3324      break;      break;
3325  #endif  #endif
3326    
     case OP_NOT_DIGIT:  
3327      case OP_DIGIT:      case OP_DIGIT:
3328      case OP_NOT_WHITESPACE:  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3329        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_digit, FALSE))
3330          return consumed;
3331    #endif
3332        any = TRUE;
3333        cc++;
3334        break;
3335    
3336      case OP_WHITESPACE:      case OP_WHITESPACE:
3337      case OP_NOT_WORDCHAR:  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3338        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_space, FALSE))
3339          return consumed;
3340    #endif
3341        any = TRUE;
3342        cc++;
3343        break;
3344    
3345      case OP_WORDCHAR:      case OP_WORDCHAR:
3346    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3347        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_word, FALSE))
3348          return consumed;
3349    #endif
3350        any = TRUE;
3351        cc++;
3352        break;
3353    
3354        case OP_NOT:
3355        case OP_NOTI:
3356        cc++;
3357        /* Fall through. */
3358        case OP_NOT_DIGIT:
3359        case OP_NOT_WHITESPACE:
3360        case OP_NOT_WORDCHAR:
3361      case OP_ANY:      case OP_ANY:
3362      case OP_ALLANY:      case OP_ALLANY:
3363    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3364        if (common->utf) return consumed;
3365    #endif
3366      any = TRUE;      any = TRUE;
3367      cc++;      cc++;
3368      break;      break;
# Line 3155  while (TRUE) Line 3370  while (TRUE)
3370  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3371      case OP_NOTPROP:      case OP_NOTPROP:
3372      case OP_PROP:      case OP_PROP:
3373    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3374        if (common->utf) return consumed;
3375    #endif
3376      any = TRUE;      any = TRUE;
3377      cc += 1 + 2;      cc += 1 + 2;
3378      break;      break;
# Line 3165  while (TRUE) Line 3383  while (TRUE)
3383      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3384      continue;      continue;
3385    
3386        case OP_NOTEXACT:
3387        case OP_NOTEXACTI:
3388    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3389        if (common->utf) return consumed;
3390    #endif
3391        any = TRUE;
3392        repeat = GET2(cc, 1);
3393        cc += 1 + IMM2_SIZE + 1;
3394        break;
3395    
3396      default:      default:
3397      return consumed;      return consumed;
3398      }      }
3399    
3400    if (any)    if (any)
3401      {      {
 #ifdef SUPPORT_UTF  
     if (common->utf) return consumed;  
 #endif  
3402  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
3403      mask = 0xff;      mask = 0xff;
3404  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
# Line 3188  while (TRUE) Line 3413  while (TRUE)
3413        {        {
3414        chars[0] = mask;        chars[0] = mask;
3415        chars[1] = mask;        chars[1] = mask;
3416          bytes[0] = 255;
3417    
3418          consumed++;
3419        if (--max_chars == 0)        if (--max_chars == 0)
3420          return consumed;          return consumed;
       consumed++;  
3421        chars += 2;        chars += 2;
3422          bytes += MAX_N_BYTES;
3423        }        }
3424      while (--repeat > 0);      while (--repeat > 0);
3425    
# Line 3205  while (TRUE) Line 3432  while (TRUE)
3432    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3433  #endif  #endif
3434    
3435    if (caseless != 0 && char_has_othercase(common, cc))    if (caseless && char_has_othercase(common, cc))
3436      {      {
3437      caseless = char_get_othercase_bit(common, cc);  #ifdef SUPPORT_UTF
3438      if (caseless == 0)      if (common->utf)
3439        return consumed;        {
3440  #ifdef COMPILE_PCRE8        GETCHAR(chr, cc);
3441      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));        if ((int)PRIV(ord2utf)(char_othercase(common, chr), othercase) != len)
3442  #else          return consumed;
3443      if ((caseless & 0x100) != 0)        }
       caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));  
3444      else      else
       caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));  
3445  #endif  #endif
3446          {
3447          chr = *cc;
3448          othercase[0] = TABLE_GET(chr, common->fcc, chr);
3449          }
3450      }      }
3451    else    else
3452      caseless = 0;      caseless = FALSE;
3453    
3454    len_save = len;    len_save = len;
3455    cc_save = cc;    cc_save = cc;
3456    while (TRUE)    while (TRUE)
3457      {      {
3458        oc = othercase;
3459      do      do
3460        {        {
3461        chr = *cc;        chr = *cc;
# Line 3233  while (TRUE) Line 3463  while (TRUE)
3463        if (SLJIT_UNLIKELY(chr == NOTACHAR))        if (SLJIT_UNLIKELY(chr == NOTACHAR))
3464          return consumed;          return consumed;
3465  #endif  #endif
3466          add_prefix_byte((pcre_uint8)chr, bytes);
3467    
3468        mask = 0;        mask = 0;
3469        if ((pcre_uint32)len == (caseless & 0xff))        if (caseless)
3470          {          {
3471          mask = caseless >> 8;          add_prefix_byte((pcre_uint8)*oc, bytes);
3472            mask = *cc ^ *oc;
3473          chr |= mask;          chr |= mask;
3474          }          }
3475    
3476    #ifdef COMPILE_PCRE32
3477          if (chars[0] == NOTACHAR && chars[1] == 0)
3478    #else
3479        if (chars[0] == NOTACHAR)        if (chars[0] == NOTACHAR)
3480    #endif
3481          {          {
3482          chars[0] = chr;          chars[0] = chr;
3483          chars[1] = mask;          chars[1] = mask;
# Line 3254  while (TRUE) Line 3491  while (TRUE)
3491          }          }
3492    
3493        len--;        len--;
3494          consumed++;
3495        if (--max_chars == 0)        if (--max_chars == 0)
3496          return consumed;          return consumed;
       consumed++;  
3497        chars += 2;        chars += 2;
3498          bytes += MAX_N_BYTES;
3499        cc++;        cc++;
3500          oc++;
3501        }        }
3502      while (len > 0);      while (len > 0);
3503    
# Line 3275  while (TRUE) Line 3514  while (TRUE)
3514    }    }
3515  }  }
3516    
 #define MAX_N_CHARS 16  
   
3517  static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)  static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3518  {  {
3519  DEFINE_COMPILER;  DEFINE_COMPILER;
3520  struct sljit_label *start;  struct sljit_label *start;
3521  struct sljit_jump *quit;  struct sljit_jump *quit;
3522  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uint32 chars[MAX_N_CHARS * 2];
3523    pcre_uint8 bytes[MAX_N_CHARS * MAX_N_BYTES];
3524  pcre_uint8 ones[MAX_N_CHARS];  pcre_uint8 ones[MAX_N_CHARS];
 pcre_uint32 mask;  
 int i, max;  
3525  int offsets[3];  int offsets[3];
3526    pcre_uint32 mask;
3527    pcre_uint8 *byte_set, *byte_set_end;
3528    int i, max, from;
3529    int range_right = -1, range_len = 3 - 1;
3530    sljit_ub *update_table = NULL;
3531    BOOL in_range;
3532    
3533    /* This is even TRUE, if both are NULL. */
3534    SLJIT_ASSERT(common->read_only_data_ptr == common->read_only_data);
3535    
3536  for (i = 0; i < MAX_N_CHARS; i++)  for (i = 0; i < MAX_N_CHARS; i++)
3537    {    {
3538    chars[i << 1] = NOTACHAR;    chars[i << 1] = NOTACHAR;
3539    chars[(i << 1) + 1] = 0;    chars[(i << 1) + 1] = 0;
3540      bytes[i * MAX_N_BYTES] = 0;
3541    }    }
3542    
3543  max = scan_prefix(common, common->start, chars, MAX_N_CHARS);  max = scan_prefix(common, common->start, chars, bytes, MAX_N_CHARS);
3544    
3545  if (max <= 1)  if (max <= 1)
3546    return FALSE;    return FALSE;
# Line 3311  for (i = 0; i < max; i++) Line 3557  for (i = 0; i < max; i++)
3557      }      }
3558    }    }
3559    
3560    in_range = FALSE;
3561    from = 0;   /* Prevent compiler "uninitialized" warning */
3562    for (i = 0; i <= max; i++)
3563      {
3564      if (in_range && (i - from) > range_len && (bytes[(i - 1) * MAX_N_BYTES] <= 4))
3565        {
3566        range_len = i - from;
3567        range_right = i - 1;
3568        }
3569    
3570      if (i < max && bytes[i * MAX_N_BYTES] < 255)
3571        {
3572        if (!in_range)
3573          {
3574          in_range = TRUE;
3575          from = i;
3576          }
3577        }
3578      else if (in_range)
3579        in_range = FALSE;
3580      }
3581    
3582    if (range_right >= 0)
3583      {
3584      /* Since no data is consumed (see the assert in the beginning
3585      of this function), this space can be reallocated. */
3586      if (common->read_only_data)
3587        SLJIT_FREE(common->read_only_data);
3588    
3589      common->read_only_data_size += 256;
3590      common->read_only_data = (sljit_uw *)SLJIT_MALLOC(common->read_only_data_size);
3591      if (common->read_only_data == NULL)
3592        return TRUE;
3593    
3594      update_table = (sljit_ub *)common->read_only_data;
3595      common->read_only_data_ptr = (sljit_uw *)(update_table + 256);
3596      memset(update_table, IN_UCHARS(range_len), 256);
3597    
3598      for (i = 0; i < range_len; i++)
3599        {
3600        byte_set = bytes + ((range_right - i) * MAX_N_BYTES);
3601        SLJIT_ASSERT(byte_set[0] > 0 && byte_set[0] < 255);
3602        byte_set_end = byte_set + byte_set[0];
3603        byte_set++;
3604        while (byte_set <= byte_set_end)
3605          {
3606          if (update_table[*byte_set] > IN_UCHARS(i))
3607            update_table[*byte_set] = IN_UCHARS(i);
3608          byte_set++;
3609          }
3610        }
3611      }
3612    
3613  offsets[0] = -1;  offsets[0] = -1;
3614  /* Scan forward. */  /* Scan forward. */
3615  for (i = 0; i < max; i++)  for (i = 0; i < max; i++)
# Line 3319  for (i = 0; i < max; i++) Line 3618  for (i = 0; i < max; i++)
3618      break;      break;
3619    }    }
3620    
3621  if (offsets[0] == -1)  if (offsets[0] < 0 && range_right < 0)
3622    return FALSE;    return FALSE;
3623    
3624  /* Scan backward. */  if (offsets[0] >= 0)
 offsets[1] = -1;  
 for (i = max - 1; i > offsets[0]; i--)  
   if (ones[i] <= 2) {  
     offsets[1] = i;  
     break;  
   }  
   
 offsets[2] = -1;  
 if (offsets[1] >= 0)  
3625    {    {
3626    /* Scan from middle. */    /* Scan backward. */
3627    for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)    offsets[1] = -1;
3628      if (ones[i] <= 2)    for (i = max - 1; i > offsets[0]; i--)
3629        if (ones[i] <= 2 && i != range_right)
3630        {        {
3631        offsets[2] = i;        offsets[1] = i;
3632        break;        break;
3633        }        }
3634    
3635    if (offsets[2] == -1)    /* This case is handled better by fast_forward_first_char. */
3636      if (offsets[1] == -1 && offsets[0] == 0 && range_right < 0)
3637        return FALSE;
3638    
3639      offsets[2] = -1;
3640      /* We only search for a middle character if there is no range check. */
3641      if (offsets[1] >= 0 && range_right == -1)
3642      {      {
3643      for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)      /* Scan from middle. */
3644        for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3645        if (ones[i] <= 2)        if (ones[i] <= 2)
3646          {          {
3647          offsets[2] = i;          offsets[2] = i;
3648          break;          break;
3649          }          }
3650    
3651        if (offsets[2] == -1)
3652          {
3653          for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3654            if (ones[i] <= 2)
3655              {
3656              offsets[2] = i;
3657              break;
3658              }
3659          }
3660      }      }
   }  
3661    
3662  SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3663  SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));    SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3664    
3665  chars[0] = chars[offsets[0] << 1];    chars[0] = chars[offsets[0] << 1];
3666  chars[1] = chars[(offsets[0] << 1) + 1];    chars[1] = chars[(offsets[0] << 1) + 1];
3667  if (offsets[2] >= 0)    if (offsets[2] >= 0)
3668    {      {
3669    chars[2] = chars[offsets[2] << 1];      chars[2] = chars[offsets[2] << 1];
3670    chars[3] = chars[(offsets[2] << 1) + 1];      chars[3] = chars[(offsets[2] << 1) + 1];
3671    }      }
3672  if (offsets[1] >= 0)    if (offsets[1] >= 0)
3673    {      {
3674    chars[4] = chars[offsets[1] << 1];      chars[4] = chars[offsets[1] << 1];
3675    chars[5] = chars[(offsets[1] << 1) + 1];      chars[5] = chars[(offsets[1] << 1) + 1];
3676        }
3677    }    }
3678    
3679  max -= 1;  max -= 1;
3680  if (firstline)  if (firstline)
3681    {    {
3682    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3683      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3684    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3685    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS(max));    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3686      quit = CMP(SLJIT_C_LESS_EQUAL, STR_END, 0, TMP1, 0);
3687      OP1(SLJIT_MOV, STR_END, 0, TMP1, 0);
3688      JUMPHERE(quit);
3689    }    }
3690  else  else
3691    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3692    
3693    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3694    if (range_right >= 0)
3695      OP1(SLJIT_MOV, RETURN_ADDR, 0, SLJIT_IMM, (sljit_sw)update_table);
3696    #endif
3697    
3698  start = LABEL();  start = LABEL();
3699  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3700    
3701  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));  SLJIT_ASSERT(range_right >= 0 || offsets[0] >= 0);
 if (offsets[1] >= 0)  
   OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
   
 if (chars[1] != 0)  
   OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);  
 CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);  
 if (offsets[2] >= 0)  
   OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));  
3702    
3703  if (offsets[1] >= 0)  if (range_right >= 0)
3704    {    {
3705    if (chars[5] != 0)  #if defined COMPILE_PCRE8 || (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
3706      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right));
3707    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);  #else
3708      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right + 1) - 1);
3709    #endif
3710    
3711    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3712      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(RETURN_ADDR, TMP1), 0);
3713    #else
3714      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)update_table);
3715    #endif
3716      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3717      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, start);
3718    }    }
3719    
3720  if (offsets[2] >= 0)  if (offsets[0] >= 0)
3721    {    {
3722    if (chars[3] != 0)    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3723      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);    if (offsets[1] >= 0)
3724    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3725      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3726    
3727      if (chars[1] != 0)
3728        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3729      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3730      if (offsets[2] >= 0)
3731        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3732    
3733      if (offsets[1] >= 0)
3734        {
3735        if (chars[5] != 0)
3736          OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3737        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3738        }
3739    
3740      if (offsets[2] >= 0)
3741        {
3742        if (chars[3] != 0)
3743          OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3744        CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3745        }
3746      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3747    }    }
 OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
3748    
3749  JUMPHERE(quit);  JUMPHERE(quit);
3750    
3751  if (firstline)  if (firstline)
3752      {
3753      if (range_right >= 0)
3754        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3755    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3756      if (range_right >= 0)
3757        {
3758        quit = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3759        OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
3760        JUMPHERE(quit);
3761        }
3762      }
3763  else  else
3764    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3765  return TRUE;  return TRUE;
3766  }  }
3767    
3768  #undef MAX_N_CHARS  #undef MAX_N_CHARS
3769    #undef MAX_N_BYTES
3770    
3771  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
3772  {  {
# Line 3522  if (common->nltype == NLTYPE_FIXED && co Line 3872  if (common->nltype == NLTYPE_FIXED && co
3872    JUMPHERE(lastchar);    JUMPHERE(lastchar);
3873    
3874    if (firstline)    if (firstline)
3875      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3876    return;    return;
3877    }    }
3878    
# Line 3532  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3882  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3882  skip_char_back(common);  skip_char_back(common);
3883    
3884  loop = LABEL();  loop = LABEL();
3885  read_char_max(common, common->nlmax, TRUE);  common->ff_newline_shortcut = loop;
3886    
3887    read_char_range(common, common->nlmin, common->nlmax, TRUE);
3888  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3889  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3890    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
# Line 3801  JUMPHERE(skipread); Line 4153  JUMPHERE(skipread);
4153    
4154  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
4155  check_str_end(common, &skipread_list);  check_str_end(common, &skipread_list);
4156  peek_char(common);  peek_char(common, READ_CHAR_MAX);
4157    
4158  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
4159  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4360  return cc; Line 4712  return cc;
4712  #define SET_TYPE_OFFSET(value) \  #define SET_TYPE_OFFSET(value) \
4713    if ((value) != typeoffset) \    if ((value) != typeoffset) \
4714      { \      { \
4715      if ((value) > typeoffset) \      if ((value) < typeoffset) \
       OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \  
     else \  
4716        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \
4717        else \
4718          OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \
4719      } \      } \
4720    typeoffset = (value);    typeoffset = (value);
4721    
4722  #define SET_CHAR_OFFSET(value) \  #define SET_CHAR_OFFSET(value) \
4723    if ((value) != charoffset) \    if ((value) != charoffset) \
4724      { \      { \
4725      if ((value) > charoffset) \      if ((value) < charoffset) \
       OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)((value) - charoffset)); \  
     else \  
4726        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(charoffset - (value))); \        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(charoffset - (value))); \
4727        else \
4728          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)((value) - charoffset)); \
4729      } \      } \
4730    charoffset = (value);    charoffset = (value);
4731    
# Line 4382  static void compile_xclass_matchingpath( Line 4734  static void compile_xclass_matchingpath(
4734  DEFINE_COMPILER;  DEFINE_COMPILER;
4735  jump_list *found = NULL;  jump_list *found = NULL;
4736  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4737  sljit_uw c, charoffset, max = 0;  sljit_uw c, charoffset, max = 256, min = READ_CHAR_MAX;
4738  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4739  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4740  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
# Line 4395  BOOL needstype = FALSE, needsscript = FA Line 4747  BOOL needstype = FALSE, needsscript = FA
4747  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4748  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4749  const pcre_uint32 *other_cases;  const pcre_uint32 *other_cases;
4750  pcre_int32 typeoffset;  sljit_uw typeoffset;
4751  #endif  #endif
4752    
4753  /* Scanning the necessary info. */  /* Scanning the necessary info. */
4754  cc++;  cc++;
4755  ccbegin = cc;  ccbegin = cc;
4756  compares = 0;  compares = 0;
4757  if (cc[-1] & XCL_MAP) cc += 32 / sizeof(pcre_uchar);  if (cc[-1] & XCL_MAP)
4758      {
4759      min = 0;
4760      cc += 32 / sizeof(pcre_uchar);
4761      }
4762    
4763  while (*cc != XCL_END)  while (*cc != XCL_END)
4764    {    {
# Line 4412  while (*cc != XCL_END) Line 4768  while (*cc != XCL_END)
4768      cc ++;      cc ++;
4769      GETCHARINCTEST(c, cc);      GETCHARINCTEST(c, cc);
4770      if (c > max) max = c;      if (c > max) max = c;
4771        if (c < min) min = c;
4772  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4773      needschar = TRUE;      needschar = TRUE;
4774  #endif  #endif
4775      }      }
4776    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4777      {      {
4778      cc += 2;      cc ++;
4779  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4780      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (c < min) min = c;
 #endif  
4781      GETCHARINCTEST(c, cc);      GETCHARINCTEST(c, cc);
4782      if (c > max) max = c;      if (c > max) max = c;
4783  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4439  while (*cc != XCL_END) Line 4795  while (*cc != XCL_END)
4795        while (*other_cases != NOTACHAR)        while (*other_cases != NOTACHAR)
4796          {          {
4797          if (*other_cases > max) max = *other_cases;          if (*other_cases > max) max = *other_cases;
4798            if (*other_cases < min) min = *other_cases;
4799          other_cases++;          other_cases++;
4800          }          }
4801        }        }
4802      else      else
4803        max = READ_CHAR_ANY;        {
4804          max = READ_CHAR_MAX;
4805          min = 0;
4806          }
4807    
4808      switch(*cc)      switch(*cc)
4809        {        {
# Line 4488  while (*cc != XCL_END) Line 4848  while (*cc != XCL_END)
4848  /* We are not necessary in utf mode even in 8 bit mode. */  /* We are not necessary in utf mode even in 8 bit mode. */
4849  cc = ccbegin;  cc = ccbegin;
4850  detect_partial_match(common, backtracks);  detect_partial_match(common, backtracks);
4851  read_char_max(common, max, (cc[0] & XCL_NOT) != 0);  read_char_range(common, min, max, (cc[-1] & XCL_NOT) != 0);
4852    
4853  if ((cc[-1] & XCL_HASPROP) == 0)  if ((cc[-1] & XCL_HASPROP) == 0)
4854    {    {
# Line 4511  if ((cc[-1] & XCL_HASPROP) == 0) Line 4871  if ((cc[-1] & XCL_HASPROP) == 0)
4871      cc += 32 / sizeof(pcre_uchar);      cc += 32 / sizeof(pcre_uchar);
4872      }      }
4873    else    else
4874      add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0xff));      {
4875        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, min);
4876        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, max - min));
4877        }
4878    }    }
4879  else if ((cc[-1] & XCL_MAP) != 0)  else if ((cc[-1] & XCL_MAP) != 0)
4880    {    {
# Line 4945  switch(type) Line 5308  switch(type)
5308    
5309    case OP_ANY:    case OP_ANY:
5310    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5311    read_char_max(common, common->nlmax, TRUE);    read_char_range(common, common->nlmin, common->nlmax, TRUE);
5312    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
5313      {      {
5314      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
# Line 5013  switch(type) Line 5376  switch(type)
5376    
5377    case OP_ANYNL:    case OP_ANYNL:
5378    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5379    read_char_max(common, common->bsr_nlmax, FALSE);    read_char_range(common, common->bsr_nlmin, common->bsr_nlmax, FALSE);
5380    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
5381    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
5382    end_list = NULL;    end_list = NULL;
# Line 5035  switch(type) Line 5398  switch(type)
5398    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
5399    case OP_HSPACE:    case OP_HSPACE:
5400    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5401    read_char_max(common, 0x3000, type == OP_NOT_HSPACE);    read_char_range(common, 0x9, 0x3000, type == OP_NOT_HSPACE);
5402    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));
5403    add_jump(compiler, backtracks, JUMP(type == OP_NOT_HSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_NOT_HSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
5404    return cc;    return cc;
# Line 5043  switch(type) Line 5406  switch(type)
5406    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
5407    case OP_VSPACE:    case OP_VSPACE:
5408    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5409    read_char_max(common, 0x2029, type == OP_NOT_VSPACE);    read_char_range(common, 0xa, 0x2029, type == OP_NOT_VSPACE);
5410    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));
5411    add_jump(compiler, backtracks, JUMP(type == OP_NOT_VSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_NOT_VSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
5412    return cc;    return cc;
# Line 5142  switch(type) Line 5505  switch(type)
5505      else      else
5506        {        {
5507        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);
5508        read_char_max(common, common->nlmax, TRUE);        read_char_range(common, common->nlmin, common->nlmax, TRUE);
5509        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, STR_END, 0));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, STR_END, 0));
5510        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
5511        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 5190  switch(type) Line 5553  switch(type)
5553    else    else
5554      {      {
5555      skip_char_back(common);      skip_char_back(common);
5556      read_char_max(common, common->nlmax, TRUE);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
5557      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5558      }      }
5559    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 5241  switch(type) Line 5604  switch(type)
5604      }      }
5605    else    else
5606      {      {
5607      peek_char(common);      peek_char(common, common->nlmax);
5608      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5609      }      }
5610    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 5278  switch(type) Line 5641  switch(type)
5641    
5642    if (type == OP_CHAR || !char_has_othercase(common, cc))    if (type == OP_CHAR || !char_has_othercase(common, cc))
5643      {      {
5644      read_char_max(common, c, FALSE);      read_char_range(common, c, c, FALSE);
5645      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c));
5646      return cc + length;      return cc + length;
5647      }      }
5648    oc = char_othercase(common, c);    oc = char_othercase(common, c);
5649    read_char_max(common, c > oc ? c : oc, FALSE);    read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, FALSE);
5650    bit = c ^ oc;    bit = c ^ oc;
5651    if (is_powerof2(bit))    if (is_powerof2(bit))
5652      {      {
# Line 5336  switch(type) Line 5699  switch(type)
5699    
5700    if (type == OP_NOT || !char_has_othercase(common, cc))    if (type == OP_NOT || !char_has_othercase(common, cc))
5701      {      {
5702      read_char_max(common, c, TRUE);      read_char_range(common, c, c, TRUE);
5703      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));
5704      }      }
5705    else    else
5706      {      {
5707      oc = char_othercase(common, c);      oc = char_othercase(common, c);
5708      read_char_max(common, c > oc ? c : oc, TRUE);      read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, TRUE);
5709      bit = c ^ oc;      bit = c ^ oc;
5710      if (is_powerof2(bit))      if (is_powerof2(bit))
5711        {        {
# Line 5363  switch(type) Line 5726  switch(type)
5726    
5727  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5728    bit = (common->utf && is_char7_bitset((const pcre_uint8 *)cc, type == OP_NCLASS)) ? 127 : 255;    bit = (common->utf && is_char7_bitset((const pcre_uint8 *)cc, type == OP_NCLASS)) ? 127 : 255;
5729    read_char_max(common, bit, type == OP_NCLASS);    read_char_range(common, 0, bit, type == OP_NCLASS);
5730  #else  #else
5731    read_char_max(common, 255, type == OP_NCLASS);    read_char_range(common, 0, 255, type == OP_NCLASS);
5732  #endif  #endif
5733    
5734    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, FALSE, backtracks))    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, FALSE, backtracks))
# Line 7052  if (ket == OP_KETRMAX) Line 7415  if (ket == OP_KETRMAX)
7415    
7416  if (repeat_type == OP_EXACT)  if (repeat_type == OP_EXACT)
7417    {    {
7418      count_match(common);
7419    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
7420    JUMPTO(SLJIT_C_NOT_ZERO, rmax_label);    JUMPTO(SLJIT_C_NOT_ZERO, rmax_label);
7421    }    }
# Line 7736  if (*cc == OP_FAIL) Line 8100  if (*cc == OP_FAIL)
8100    return cc + 1;    return cc + 1;
8101    }    }
8102    
8103  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL || !common->might_be_empty)
8104    {    {
8105    /* No need to check notempty conditions. */    /* No need to check notempty conditions. */
8106    if (common->accept_label == NULL)    if (common->accept_label == NULL)
# Line 8438  if (bra == OP_BRAZERO) Line 8802  if (bra == OP_BRAZERO)
8802  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8803  {  {
8804  DEFINE_COMPILER;  DEFINE_COMPILER;
8805  int opcode, stacksize, count;  int opcode, stacksize, alt_count, alt_max;
8806  int offset = 0;  int offset = 0;
8807  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;
8808  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;
8809  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
8810  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
8811  pcre_uchar *ccprev;  pcre_uchar *ccprev;
 jump_list *jumplist = NULL;  
 jump_list *jumplistitem = NULL;  
8812  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
8813  pcre_uchar ket;  pcre_uchar ket;
8814  assert_backtrack *assert;  assert_backtrack *assert;
8815    sljit_uw *next_update_addr = NULL;
8816  BOOL has_alternatives;  BOOL has_alternatives;
8817  BOOL needs_control_head = FALSE;  BOOL needs_control_head = FALSE;
8818  struct sljit_jump *brazero = NULL;  struct sljit_jump *brazero = NULL;
8819    struct sljit_jump *alt1 = NULL;
8820    struct sljit_jump *alt2 = NULL;
8821  struct sljit_jump *once = NULL;  struct sljit_jump *once = NULL;
8822  struct sljit_jump *cond = NULL;  struct sljit_jump *cond = NULL;
8823  struct sljit_label *rmin_label = NULL;  struct sljit_label *rmin_label = NULL;
# Line 8490  if (SLJIT_UNLIKELY(opcode == OP_COND) && Line 8855  if (SLJIT_UNLIKELY(opcode == OP_COND) &&
8855  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))
8856    opcode = OP_ONCE;    opcode = OP_ONCE;
8857    
8858    alt_max = has_alternatives ? no_alternatives(ccbegin) : 0;
8859    
8860  /* Decoding the needs_control_head in framesize. */  /* Decoding the needs_control_head in framesize. */
8861  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
8862    {    {
# Line 8603  else if (SLJIT_UNLIKELY(opcode == OP_CON Line 8970  else if (SLJIT_UNLIKELY(opcode == OP_CON
8970      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8971      free_stack(common, 1);      free_stack(common, 1);
8972    
8973      jumplistitem = sljit_alloc_memory(compiler, sizeof(jump_list));      alt_max = 2;
8974      if (SLJIT_UNLIKELY(!jumplistitem))      alt1 = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, sizeof(sljit_uw));
       return;  
     jumplist = jumplistitem;  
     jumplistitem->next = NULL;  
     jumplistitem->jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 1);  
8975      }      }
8976    }    }
8977  else if (*cc == OP_ALT)  else if (has_alternatives)
8978    {    {
   /* Build a jump list. Get the last successfully matched branch index. */  
8979    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8980    free_stack(common, 1);    free_stack(common, 1);
   count = 1;  
   do  
     {  
     /* Append as the last item. */  
     if (jumplist != NULL)  
       {  
       jumplistitem->next = sljit_alloc_memory(compiler, sizeof(jump_list));  
       jumplistitem = jumplistitem->next;  
       }  
     else  
       {  
       jumplistitem = sljit_alloc_memory(compiler, sizeof(jump_list));  
       jumplist = jumplistitem;  
       }  
8981    
8982      if (SLJIT_UNLIKELY(!jumplistitem))    if (alt_max > 4)
8983        return;      {
8984        /* Table jump if alt_max is greater than 4. */
8985      jumplistitem->next = NULL;      next_update_addr = common->read_only_data_ptr;
8986      jumplistitem->jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, count++);      common->read_only_data_ptr += alt_max;
8987      cc += GET(cc, 1);      sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM1(TMP1), (sljit_sw)next_update_addr);
8988        add_label_addr(common, next_update_addr++);
8989        }
8990      else
8991        {
8992        if (alt_max == 4)
8993          alt2 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_uw));
8994        alt1 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, sizeof(sljit_uw));
8995      }      }
   while (*cc == OP_ALT);  
   
   cc = ccbegin + GET(ccbegin, 1);  
8996    }    }
8997    
8998  COMPILE_BACKTRACKINGPATH(current->top);  COMPILE_BACKTRACKINGPATH(current->top);
# Line 8675  if (SLJIT_UNLIKELY(opcode == OP_COND) || Line 9027  if (SLJIT_UNLIKELY(opcode == OP_COND) ||
9027    
9028  if (has_alternatives)  if (has_alternatives)
9029    {    {
9030    count = 1;    alt_count = sizeof(sljit_uw);
9031    do    do
9032      {      {
9033      current->top = NULL;      current->top = NULL;
# Line 8751  if (has_alternatives) Line 9103  if (has_alternatives)
9103        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
9104    
9105      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
9106        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, alt_count);
9107    
9108      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)
9109        {        {
# Line 8764  if (has_alternatives) Line 9116  if (has_alternatives)
9116    
9117      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
9118        {        {
9119        SLJIT_ASSERT(jumplist);        if (alt_max > 4)
9120        JUMPHERE(jumplist->jump);          add_label_addr(common, next_update_addr++);
9121        jumplist = jumplist->next;        else
9122            {
9123            if (alt_count != 2 * sizeof(sljit_uw))
9124              {
9125              JUMPHERE(alt1);
9126              if (alt_max == 3 && alt_count == sizeof(sljit_uw))
9127                alt2 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_uw));
9128              }
9129            else
9130              {
9131              JUMPHERE(alt2);
9132              if (alt_max == 4)
9133                alt1 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_uw));
9134              }
9135            }
9136          alt_count += sizeof(sljit_uw);
9137        }        }
9138    
9139      COMPILE_BACKTRACKINGPATH(current->top);      COMPILE_BACKTRACKINGPATH(current->top);
# Line 8775  if (has_alternatives) Line 9142  if (has_alternatives)
9142      SLJIT_ASSERT(!current->nextbacktracks);      SLJIT_ASSERT(!current->nextbacktracks);
9143      }      }
9144    while (*cc == OP_ALT);    while (*cc == OP_ALT);
   SLJIT_ASSERT(!jumplist);  
9145    
9146    if (cond != NULL)    if (cond != NULL)
9147      {      {
# Line 9376  pcre_uchar *ccend; Line 9742  pcre_uchar *ccend;
9742  executable_functions *functions;  executable_functions *functions;
9743  void *executable_func;  void *executable_func;
9744  sljit_uw executable_size;  sljit_uw executable_size;
9745    sljit_uw total_length;
9746    label_addr_list *label_addr;
9747  struct sljit_label *mainloop_label = NULL;  struct sljit_label *mainloop_label = NULL;
9748  struct sljit_label *continue_match_label;  struct sljit_label *continue_match_label;
9749  struct sljit_label *empty_match_found_label;  struct sljit_label *empty_match_found_label = NULL;
9750  struct sljit_label *empty_match_backtrack_label;  struct sljit_label *empty_match_backtrack_label = NULL;
9751  struct sljit_label *reset_match_label;  struct sljit_label *reset_match_label;
9752    struct sljit_label *quit_label;
9753  struct sljit_jump *jump;  struct sljit_jump *jump;
9754  struct sljit_jump *minlength_check_failed = NULL;  struct sljit_jump *minlength_check_failed = NULL;
9755  struct sljit_jump *reqbyte_notfound = NULL;  struct sljit_jump *reqbyte_notfound = NULL;
9756  struct sljit_jump *empty_match;  struct sljit_jump *empty_match = NULL;
 struct sljit_label *quit_label;  
9757    
9758  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);
9759  study = extra->study_data;  study = extra->study_data;
# Line 9398  memset(common, 0, sizeof(compiler_common Line 9766  memset(common, 0, sizeof(compiler_common
9766  rootbacktrack.cc = (pcre_uchar *)re + re->name_table_offset + re->name_count * re->name_entry_size;  rootbacktrack.cc = (pcre_uchar *)re + re->name_table_offset + re->name_count * re->name_entry_size;
9767    
9768  common->start = rootbacktrack.cc;  common->start = rootbacktrack.cc;
9769    common->read_only_data = NULL;
9770    common->read_only_data_size = 0;
9771    common->read_only_data_ptr = NULL;
9772  common->fcc = tables + fcc_offset;  common->fcc = tables + fcc_offset;
9773  common->lcc = (sljit_sw)(tables + lcc_offset);  common->lcc = (sljit_sw)(tables + lcc_offset);
9774  common->mode = mode;  common->mode = mode;
9775    common->might_be_empty = study->minlength == 0;
9776  common->nltype = NLTYPE_FIXED;  common->nltype = NLTYPE_FIXED;
9777  switch(re->options & PCRE_NEWLINE_BITS)  switch(re->options & PCRE_NEWLINE_BITS)
9778    {    {
# Line 9421  switch(re->options & PCRE_NEWLINE_BITS) Line 9793  switch(re->options & PCRE_NEWLINE_BITS)
9793    case PCRE_NEWLINE_ANYCRLF: common->newline = (CHAR_CR << 8) | CHAR_NL; common->nltype = NLTYPE_ANYCRLF; break;    case PCRE_NEWLINE_ANYCRLF: common->newline = (CHAR_CR << 8) | CHAR_NL; common->nltype = NLTYPE_ANYCRLF; break;
9794    default: return;    default: return;
9795    }    }
9796  common->nlmax = READ_CHAR_ANY;  common->nlmax = READ_CHAR_MAX;
9797    common->nlmin = 0;
9798  if ((re->options & PCRE_BSR_ANYCRLF) != 0)  if ((re->options & PCRE_BSR_ANYCRLF) != 0)
9799    common->bsr_nltype = NLTYPE_ANYCRLF;    common->bsr_nltype = NLTYPE_ANYCRLF;
9800  else if ((re->options & PCRE_BSR_UNICODE) != 0)  else if ((re->options & PCRE_BSR_UNICODE) != 0)
# Line 9434  else Line 9807  else
9807    common->bsr_nltype = NLTYPE_ANY;    common->bsr_nltype = NLTYPE_ANY;
9808  #endif  #endif
9809    }    }
9810  common->bsr_nlmax = READ_CHAR_ANY;  common->bsr_nlmax = READ_CHAR_MAX;
9811    common->bsr_nlmin = 0;
9812  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
9813  common->ctypes = (sljit_sw)(tables + ctypes_offset);  common->ctypes = (sljit_sw)(tables + ctypes_offset);
9814  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;
# Line 9459  if (common->utf) Line 9833  if (common->utf)
9833      common->nlmax = common->newline & 0xff;      common->nlmax = common->newline & 0xff;
9834      }      }
9835    
9836      if (common->nltype == NLTYPE_FIXED)
9837        common->nlmin = common->newline & 0xff;
9838      else
9839        common->nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL;
9840    
9841    if (common->bsr_nltype == NLTYPE_ANY)    if (common->bsr_nltype == NLTYPE_ANY)
9842      common->bsr_nlmax = 0x2029;      common->bsr_nlmax = 0x2029;
9843    else    else
9844      common->bsr_nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;      common->bsr_nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;
9845      common->bsr_nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL;
9846    }    }
9847  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
9848  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(common->start);
9849    
9850  /* Calculate the local space size on the stack. */  /* Calculate the local space size on the stack. */
9851  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);
# Line 9478  memset(common->optimized_cbracket, 0, re Line 9858  memset(common->optimized_cbracket, 0, re
9858  memset(common->optimized_cbracket, 1, re->top_bracket + 1);  memset(common->optimized_cbracket, 1, re->top_bracket + 1);
9859  #endif  #endif
9860    
9861  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);  SLJIT_ASSERT(*common->start == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);
9862  #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2  #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2
9863  common->capture_last_ptr = common->ovector_start;  common->capture_last_ptr = common->ovector_start;
9864  common->ovector_start += sizeof(sljit_sw);  common->ovector_start += sizeof(sljit_sw);
9865  #endif  #endif
9866  if (!check_opcode_types(common, rootbacktrack.cc, ccend))  if (!check_opcode_types(common, common->start, ccend))
9867    {    {
9868    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9869    return;    return;
# Line 9546  if (common->capture_last_ptr != 0) Line 9926  if (common->capture_last_ptr != 0)
9926  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));
9927  common->cbra_ptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);  common->cbra_ptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);
9928    
9929  common->private_data_ptrs = (int *)SLJIT_MALLOC((ccend - rootbacktrack.cc) * sizeof(sljit_si));  total_length = ccend - common->start;
9930    common->private_data_ptrs = (sljit_si *)SLJIT_MALLOC(total_length * (sizeof(sljit_si) + (common->has_then ? 1 : 0)));
9931  if (!common->private_data_ptrs)  if (!common->private_data_ptrs)
9932    {    {
9933    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9934    return;    return;
9935    }    }
9936  memset(common->private_data_ptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));  memset(common->private_data_ptrs, 0, total_length * sizeof(sljit_si));
9937    
9938  private_data_size = common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw);  private_data_size = common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw);
9939  set_private_data_ptrs(common, &private_data_size, ccend);  set_private_data_ptrs(common, &private_data_size, ccend);
# Line 9565  if (private_data_size > SLJIT_MAX_LOCAL_ Line 9946  if (private_data_size > SLJIT_MAX_LOCAL_
9946    
9947  if (common->has_then)  if (common->has_then)
9948    {    {
9949    common->then_offsets = (pcre_uint8 *)SLJIT_MALLOC(ccend - rootbacktrack.cc);    common->then_offsets = (pcre_uint8 *)(common->private_data_ptrs + total_length);
9950    if (!common->then_offsets)    memset(common->then_offsets, 0, total_length);
9951      set_then_offsets(common, common->start, NULL);
9952      }
9953    
9954    if (common->read_only_data_size > 0)
9955      {
9956      common->read_only_data = (sljit_uw *)SLJIT_MALLOC(common->read_only_data_size);
9957      if (common->read_only_data == NULL)
9958      {      {
9959      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
9960      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
9961      return;      return;
9962      }      }
9963    memset(common->then_offsets, 0, ccend - rootbacktrack.cc);    common->read_only_data_ptr = common->read_only_data;
   set_then_offsets(common, rootbacktrack.cc, NULL);  
9964    }    }
9965    
9966  compiler = sljit_create_compiler();  compiler = sljit_create_compiler();
# Line 9581  if (!compiler) Line 9968  if (!compiler)
9968    {    {
9969    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9970    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9971    if (common->has_then)    if (common->read_only_data)
9972      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
9973    return;    return;
9974    }    }
9975  common->compiler = compiler;  common->compiler = compiler;
# Line 9621  if ((re->options & PCRE_ANCHORED) == 0) Line 10008  if ((re->options & PCRE_ANCHORED) == 0)
10008    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)
10009      {      {
10010      if (mode == JIT_COMPILE && fast_forward_first_n_chars(common, (re->options & PCRE_FIRSTLINE) != 0))      if (mode == JIT_COMPILE && fast_forward_first_n_chars(common, (re->options & PCRE_FIRSTLINE) != 0))
10011        { /* Do nothing */ }        {
10012          /* If read_only_data is reallocated, we might have an allocation failure. */
10013          if (common->read_only_data_size > 0 && common->read_only_data == NULL)
10014            {
10015            sljit_free_compiler(compiler);
10016            SLJIT_FREE(common->optimized_cbracket);
10017            SLJIT_FREE(common->private_data_ptrs);
10018            return;
10019            }
10020          }
10021      else if ((re->flags & PCRE_FIRSTSET) != 0)      else if ((re->flags & PCRE_FIRSTSET) != 0)
10022        fast_forward_first_char(common, (pcre_uchar)re->first_char, (re->flags & PCRE_FCH_CASELESS) != 0, (re->options & PCRE_FIRSTLINE) != 0);        fast_forward_first_char(common, (pcre_uchar)re->first_char, (re->flags & PCRE_FCH_CASELESS) != 0, (re->options & PCRE_FIRSTLINE) != 0);
10023      else if ((re->flags & PCRE_STARTLINE) != 0)      else if ((re->flags & PCRE_STARTLINE) != 0)
# Line 9668  if (mode == JIT_PARTIAL_SOFT_COMPILE) Line 10064  if (mode == JIT_PARTIAL_SOFT_COMPILE)
10064  else if (mode == JIT_PARTIAL_HARD_COMPILE)  else if (mode == JIT_PARTIAL_HARD_COMPILE)
10065    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
10066    
10067  compile_matchingpath(common, rootbacktrack.cc, ccend, &rootbacktrack);  compile_matchingpath(common, common->start, ccend, &rootbacktrack);
10068  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
10069    {    {
10070    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
10071    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
10072    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
10073    if (common->has_then)    if (common->read_only_data)
10074      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
10075    return;    return;
10076    }    }
10077    
10078  empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));  if (common->might_be_empty)
10079  empty_match_found_label = LABEL();    {
10080      empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
10081      empty_match_found_label = LABEL();
10082      }
10083    
10084  common->accept_label = LABEL();  common->accept_label = LABEL();
10085  if (common->accept != NULL)  if (common->accept != NULL)
# Line 9704  if (mode != JIT_COMPILE) Line 10103  if (mode != JIT_COMPILE)
10103    return_with_partial_match(common, common->quit_label);    return_with_partial_match(common, common->quit_label);
10104    }    }
10105    
10106  empty_match_backtrack_label = LABEL();  if (common->might_be_empty)
10107      empty_match_backtrack_label = LABEL();
10108  compile_backtrackingpath(common, rootbacktrack.top);  compile_backtrackingpath(common, rootbacktrack.top);
10109  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
10110    {    {
10111    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
10112    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
10113    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
10114    if (common->has_then)    if (common->read_only_data)
10115      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
10116    return;    return;
10117    }    }
10118    
# Line 9740  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SL Line 10140  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SL
10140    
10141  if ((re->options & PCRE_ANCHORED) == 0)  if ((re->options & PCRE_ANCHORED) == 0)
10142    {    {
10143    if ((re->options & PCRE_FIRSTLINE) == 0)    if (common->ff_newline_shortcut != NULL)
10144      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop_label);      {
10145        if ((re->options & PCRE_FIRSTLINE) == 0)
10146          CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, common->ff_newline_shortcut);
10147        /* There cannot be more newlines here. */
10148        }
10149    else    else
10150      CMPTO(SLJIT_C_LESS, STR_PTR, 0, TMP1, 0, mainloop_label);      {
10151        if ((re->options & PCRE_FIRSTLINE) == 0)
10152          CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop_label);
10153        else
10154          CMPTO(SLJIT_C_LESS, STR_PTR, 0, TMP1, 0, mainloop_label);
10155        }
10156    }    }
10157    
10158  /* No more remaining characters. */  /* No more remaining characters. */
# Line 9758  JUMPTO(SLJIT_JUMP, common->quit_label); Line 10167  JUMPTO(SLJIT_JUMP, common->quit_label);
10167    
10168  flush_stubs(common);  flush_stubs(common);
10169    
10170  JUMPHERE(empty_match);  if (common->might_be_empty)
10171  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);    {
10172  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));    JUMPHERE(empty_match);
10173  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_backtrack_label);    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
10174  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));
10175  CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_found_label);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_backtrack_label);
10176  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));
10177  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, empty_match_found_label);    CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_found_label);
10178  JUMPTO(SLJIT_JUMP, empty_match_backtrack_label);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
10179      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, empty_match_found_label);
10180      JUMPTO(SLJIT_JUMP, empty_match_backtrack_label);
10181      }
10182    
10183  common->currententry = common->entries;  common->currententry = common->entries;
10184  common->local_exit = TRUE;  common->local_exit = TRUE;
# Line 9780  while (common->currententry != NULL) Line 10192  while (common->currententry != NULL)
10192      sljit_free_compiler(compiler);      sljit_free_compiler(compiler);
10193      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
10194      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
10195      if (common->has_then)      if (common->read_only_data)
10196        SLJIT_FREE(common->then_offsets);        SLJIT_FREE(common->read_only_data);
10197      return;      return;
10198      }      }
10199    flush_stubs(common);    flush_stubs(common);
# Line 9891  if (common->getucd != NULL) Line 10303  if (common->getucd != NULL)
10303    }    }
10304  #endif  #endif
10305    
10306    SLJIT_ASSERT(common->read_only_data + (common->read_only_data_size >> SLJIT_WORD_SHIFT) == common->read_only_data_ptr);
10307  SLJIT_FREE(common->optimized_cbracket);  SLJIT_FREE(common->optimized_cbracket);
10308  SLJIT_FREE(common->private_data_ptrs);  SLJIT_FREE(common->private_data_ptrs);
 if (common->has_then)  
   SLJIT_FREE(common->then_offsets);  
10309    
10310  executable_func = sljit_generate_code(compiler);  executable_func = sljit_generate_code(compiler);
10311  executable_size = sljit_get_generated_code_size(compiler);  executable_size = sljit_get_generated_code_size(compiler);
10312    label_addr = common->label_addrs;
10313    while (label_addr != NULL)
10314      {
10315      *label_addr->update_addr = sljit_get_label_addr(label_addr->label);
10316      label_addr = label_addr->next;
10317      }
10318  sljit_free_compiler(compiler);  sljit_free_compiler(compiler);
10319  if (executable_func == NULL)  if (executable_func == NULL)
10320      {
10321      if (common->read_only_data)
10322        SLJIT_FREE(common->read_only_data);
10323    return;    return;
10324      }
10325    
10326  /* Reuse the function descriptor if possible. */  /* Reuse the function descriptor if possible. */
10327  if ((extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 && extra->executable_jit != NULL)  if ((extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 && extra->executable_jit != NULL)
# Line 9920  else Line 10341  else
10341    if (functions == NULL)    if (functions == NULL)
10342      {      {
10343      /* This case is highly unlikely since we just recently      /* This case is highly unlikely since we just recently
10344      freed a lot of memory. Although not impossible. */      freed a lot of memory. Not impossible though. */
10345      sljit_free_code(executable_func);      sljit_free_code(executable_func);
10346        if (common->read_only_data)
10347          SLJIT_FREE(common->read_only_data);
10348      return;      return;
10349      }      }
10350    memset(functions, 0, sizeof(executable_functions));    memset(functions, 0, sizeof(executable_functions));
# Line 9932  else Line 10355  else
10355    }    }
10356    
10357  functions->executable_funcs[mode] = executable_func;  functions->executable_funcs[mode] = executable_func;
10358    functions->read_only_data[mode] = common->read_only_data;
10359  functions->executable_sizes[mode] = executable_size;  functions->executable_sizes[mode] = executable_size;
10360  }  }
10361    
# Line 10118  for (i = 0; i < JIT_NUMBER_OF_COMPILE_MO Line 10542  for (i = 0; i < JIT_NUMBER_OF_COMPILE_MO
10542    {    {
10543    if (functions->executable_funcs[i] != NULL)    if (functions->executable_funcs[i] != NULL)
10544      sljit_free_code(functions->executable_funcs[i]);      sljit_free_code(functions->executable_funcs[i]);
10545      if (functions->read_only_data[i] != NULL)
10546        SLJIT_FREE(functions->read_only_data[i]);
10547    }    }
10548  SLJIT_FREE(functions);  SLJIT_FREE(functions);
10549  }  }

Legend:
Removed from v.1424  
changed lines
  Added in v.1476

  ViewVC Help
Powered by ViewVC 1.1.5