home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.3 / 7.3.1140 < prev    next >
Encoding:
Internet Message Format  |  2013-06-06  |  5.2 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.3.1140
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.3.1140
  11. Problem:    New regexp engine: trying expensive match while the result is not
  12.         going to be used.
  13. Solution:   Check for output state already being in the state list.
  14. Files:        src/regexp_nfa.c
  15.  
  16.  
  17. *** ../vim-7.3.1139/src/regexp_nfa.c    2013-06-07 16:31:44.000000000 +0200
  18. --- src/regexp_nfa.c    2013-06-07 17:16:31.000000000 +0200
  19. ***************
  20. *** 3156,3161 ****
  21. --- 3156,3163 ----
  22.   static void copy_sub __ARGS((regsub_T *to, regsub_T *from));
  23.   static void copy_sub_off __ARGS((regsub_T *to, regsub_T *from));
  24.   static int sub_equal __ARGS((regsub_T *sub1, regsub_T *sub2));
  25. + static int has_state_with_pos __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs));
  26. + static int state_in_list __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs));
  27.   static void addstate __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs, int off));
  28.   static void addstate_here __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs, nfa_pim_T *pim, int *ip));
  29.   
  30. ***************
  31. *** 3319,3324 ****
  32. --- 3321,3371 ----
  33.   }
  34.   #endif
  35.   
  36. + /*
  37. +  * Return TRUE if the same state is already in list "l" with the same
  38. +  * positions as "subs".
  39. +  */
  40. +     static int
  41. + has_state_with_pos(l, state, subs)
  42. +     nfa_list_T        *l;    /* runtime state list */
  43. +     nfa_state_T        *state;    /* state to update */
  44. +     regsubs_T        *subs;    /* pointers to subexpressions */
  45. + {
  46. +     nfa_thread_T    *thread;
  47. +     int            i;
  48. +     for (i = 0; i < l->n; ++i)
  49. +     {
  50. +     thread = &l->t[i];
  51. +     if (thread->state->id == state->id
  52. +         && sub_equal(&thread->subs.norm, &subs->norm)
  53. + #ifdef FEAT_SYN_HL
  54. +         && (!nfa_has_zsubexpr ||
  55. +                sub_equal(&thread->subs.synt, &subs->synt))
  56. + #endif
  57. +                   )
  58. +         return TRUE;
  59. +     }
  60. +     return FALSE;
  61. + }
  62. + /*
  63. +  * Return TRUE if "state" is already in list "l".
  64. +  */
  65. +     static int
  66. + state_in_list(l, state, subs)
  67. +     nfa_list_T        *l;    /* runtime state list */
  68. +     nfa_state_T        *state;    /* state to update */
  69. +     regsubs_T        *subs;    /* pointers to subexpressions */
  70. + {
  71. +     if (state->lastlist[nfa_ll_index] == l->id)
  72. +     {
  73. +     if (!nfa_has_backref || has_state_with_pos(l, state, subs))
  74. +         return TRUE;
  75. +     }
  76. +     return FALSE;
  77. + }
  78.       static void
  79.   addstate(l, state, subs, off)
  80.       nfa_list_T        *l;    /* runtime state list */
  81. ***************
  82. *** 3431,3450 ****
  83.               return;
  84.           }
  85.   
  86. !         /* See if the same state is already in the list with the same
  87. !          * positions. */
  88. !         for (i = 0; i < l->n; ++i)
  89. !         {
  90. !             thread = &l->t[i];
  91. !             if (thread->state->id == state->id
  92. !                 && sub_equal(&thread->subs.norm, &subs->norm)
  93. ! #ifdef FEAT_SYN_HL
  94. !                 && (!nfa_has_zsubexpr ||
  95. !                    sub_equal(&thread->subs.synt, &subs->synt))
  96. ! #endif
  97. !                       )
  98. !             goto skip_add;
  99. !         }
  100.           }
  101.   
  102.           /* when there are backreferences or look-behind matches the number
  103. --- 3478,3485 ----
  104.               return;
  105.           }
  106.   
  107. !         if (has_state_with_pos(l, state, subs))
  108. !             goto skip_add;
  109.           }
  110.   
  111.           /* when there are backreferences or look-behind matches the number
  112. ***************
  113. *** 4600,4605 ****
  114. --- 4635,4681 ----
  115.           break;
  116.   
  117.           case NFA_START_PATTERN:
  118. +           {
  119. +         nfa_state_T *skip = NULL;
  120. + #ifdef ENABLE_LOG
  121. +         int        skip_lid = 0;
  122. + #endif
  123. +         /* There is no point in trying to match the pattern if the
  124. +          * output state is not going to be added to the list. */
  125. +         if (state_in_list(nextlist, t->state->out1->out, &t->subs))
  126. +         {
  127. +             skip = t->state->out1->out;
  128. + #ifdef ENABLE_LOG
  129. +             skip_lid = nextlist->id;
  130. + #endif
  131. +         }
  132. +         else if (state_in_list(nextlist,
  133. +                       t->state->out1->out->out, &t->subs))
  134. +         {
  135. +             skip = t->state->out1->out->out;
  136. + #ifdef ENABLE_LOG
  137. +             skip_lid = nextlist->id;
  138. + #endif
  139. +         }
  140. +         else if(state_in_list(thislist,
  141. +                       t->state->out1->out->out, &t->subs))
  142. +         {
  143. +             skip = t->state->out1->out->out;
  144. + #ifdef ENABLE_LOG
  145. +             skip_lid = thislist->id;
  146. + #endif
  147. +         }
  148. +         if (skip != NULL)
  149. +         {
  150. + #ifdef ENABLE_LOG
  151. +             nfa_set_code(skip->c);
  152. +             fprintf(log_fd, "> Not trying to match pattern, output state %d is already in list %d. char %d: %s\n",
  153. +                 abs(skip->id), skip_lid, skip->c, code);
  154. + #endif
  155. +             break;
  156. +         }
  157.           /* First try matching the pattern. */
  158.           result = recursive_regmatch(t->state, prog,
  159.                                  submatch, m, &listids);
  160. ***************
  161. *** 4654,4659 ****
  162. --- 4730,4736 ----
  163.               }
  164.           }
  165.           break;
  166. +           }
  167.   
  168.           case NFA_BOL:
  169.           if (reginput == regline)
  170. *** ../vim-7.3.1139/src/version.c    2013-06-07 16:31:45.000000000 +0200
  171. --- src/version.c    2013-06-07 17:30:12.000000000 +0200
  172. ***************
  173. *** 730,731 ****
  174. --- 730,733 ----
  175.   {   /* Add new patch number below this line */
  176. + /**/
  177. +     1140,
  178.   /**/
  179.  
  180. -- 
  181. From "know your smileys":
  182.  :-*    A big kiss!
  183.  
  184.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  185. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  186. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  187.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  188.