Karsten Hopp 514794
To: vim_dev@googlegroups.com
Karsten Hopp 514794
Subject: Patch 7.3.1140
Karsten Hopp 514794
Fcc: outbox
Karsten Hopp 514794
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 514794
Mime-Version: 1.0
Karsten Hopp 514794
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 514794
Content-Transfer-Encoding: 8bit
Karsten Hopp 514794
------------
Karsten Hopp 514794
Karsten Hopp 514794
Patch 7.3.1140
Karsten Hopp 514794
Problem:    New regexp engine: trying expensive match while the result is not
Karsten Hopp 514794
	    going to be used.
Karsten Hopp 514794
Solution:   Check for output state already being in the state list.
Karsten Hopp 514794
Files:	    src/regexp_nfa.c
Karsten Hopp 514794
Karsten Hopp 514794
Karsten Hopp 514794
*** ../vim-7.3.1139/src/regexp_nfa.c	2013-06-07 16:31:44.000000000 +0200
Karsten Hopp 514794
--- src/regexp_nfa.c	2013-06-07 17:16:31.000000000 +0200
Karsten Hopp 514794
***************
Karsten Hopp 514794
*** 3156,3161 ****
Karsten Hopp 514794
--- 3156,3163 ----
Karsten Hopp 514794
  static void copy_sub __ARGS((regsub_T *to, regsub_T *from));
Karsten Hopp 514794
  static void copy_sub_off __ARGS((regsub_T *to, regsub_T *from));
Karsten Hopp 514794
  static int sub_equal __ARGS((regsub_T *sub1, regsub_T *sub2));
Karsten Hopp 514794
+ static int has_state_with_pos __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs));
Karsten Hopp 514794
+ static int state_in_list __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs));
Karsten Hopp 514794
  static void addstate __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs, int off));
Karsten Hopp 514794
  static void addstate_here __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs, nfa_pim_T *pim, int *ip));
Karsten Hopp 514794
  
Karsten Hopp 514794
***************
Karsten Hopp 514794
*** 3319,3324 ****
Karsten Hopp 514794
--- 3321,3371 ----
Karsten Hopp 514794
  }
Karsten Hopp 514794
  #endif
Karsten Hopp 514794
  
Karsten Hopp 514794
+ /*
Karsten Hopp 514794
+  * Return TRUE if the same state is already in list "l" with the same
Karsten Hopp 514794
+  * positions as "subs".
Karsten Hopp 514794
+  */
Karsten Hopp 514794
+     static int
Karsten Hopp 514794
+ has_state_with_pos(l, state, subs)
Karsten Hopp 514794
+     nfa_list_T		*l;	/* runtime state list */
Karsten Hopp 514794
+     nfa_state_T		*state;	/* state to update */
Karsten Hopp 514794
+     regsubs_T		*subs;	/* pointers to subexpressions */
Karsten Hopp 514794
+ {
Karsten Hopp 514794
+     nfa_thread_T	*thread;
Karsten Hopp 514794
+     int			i;
Karsten Hopp 514794
+ 
Karsten Hopp 514794
+     for (i = 0; i < l->n; ++i)
Karsten Hopp 514794
+     {
Karsten Hopp 514794
+ 	thread = &l->t[i];
Karsten Hopp 514794
+ 	if (thread->state->id == state->id
Karsten Hopp 514794
+ 		&& sub_equal(&thread->subs.norm, &subs->norm)
Karsten Hopp 514794
+ #ifdef FEAT_SYN_HL
Karsten Hopp 514794
+ 		&& (!nfa_has_zsubexpr ||
Karsten Hopp 514794
+ 		       sub_equal(&thread->subs.synt, &subs->synt))
Karsten Hopp 514794
+ #endif
Karsten Hopp 514794
+ 			      )
Karsten Hopp 514794
+ 	    return TRUE;
Karsten Hopp 514794
+     }
Karsten Hopp 514794
+     return FALSE;
Karsten Hopp 514794
+ }
Karsten Hopp 514794
+ 
Karsten Hopp 514794
+ /*
Karsten Hopp 514794
+  * Return TRUE if "state" is already in list "l".
Karsten Hopp 514794
+  */
Karsten Hopp 514794
+     static int
Karsten Hopp 514794
+ state_in_list(l, state, subs)
Karsten Hopp 514794
+     nfa_list_T		*l;	/* runtime state list */
Karsten Hopp 514794
+     nfa_state_T		*state;	/* state to update */
Karsten Hopp 514794
+     regsubs_T		*subs;	/* pointers to subexpressions */
Karsten Hopp 514794
+ {
Karsten Hopp 514794
+     if (state->lastlist[nfa_ll_index] == l->id)
Karsten Hopp 514794
+     {
Karsten Hopp 514794
+ 	if (!nfa_has_backref || has_state_with_pos(l, state, subs))
Karsten Hopp 514794
+ 	    return TRUE;
Karsten Hopp 514794
+     }
Karsten Hopp 514794
+     return FALSE;
Karsten Hopp 514794
+ }
Karsten Hopp 514794
+ 
Karsten Hopp 514794
      static void
Karsten Hopp 514794
  addstate(l, state, subs, off)
Karsten Hopp 514794
      nfa_list_T		*l;	/* runtime state list */
Karsten Hopp 514794
***************
Karsten Hopp 514794
*** 3431,3450 ****
Karsten Hopp 514794
  		    return;
Karsten Hopp 514794
  		}
Karsten Hopp 514794
  
Karsten Hopp 514794
! 		/* See if the same state is already in the list with the same
Karsten Hopp 514794
! 		 * positions. */
Karsten Hopp 514794
! 		for (i = 0; i < l->n; ++i)
Karsten Hopp 514794
! 		{
Karsten Hopp 514794
! 		    thread = &l->t[i];
Karsten Hopp 514794
! 		    if (thread->state->id == state->id
Karsten Hopp 514794
! 			    && sub_equal(&thread->subs.norm, &subs->norm)
Karsten Hopp 514794
! #ifdef FEAT_SYN_HL
Karsten Hopp 514794
! 			    && (!nfa_has_zsubexpr ||
Karsten Hopp 514794
! 				   sub_equal(&thread->subs.synt, &subs->synt))
Karsten Hopp 514794
! #endif
Karsten Hopp 514794
! 					  )
Karsten Hopp 514794
! 			goto skip_add;
Karsten Hopp 514794
! 		}
Karsten Hopp 514794
  	    }
Karsten Hopp 514794
  
Karsten Hopp 514794
  	    /* when there are backreferences or look-behind matches the number
Karsten Hopp 514794
--- 3478,3485 ----
Karsten Hopp 514794
  		    return;
Karsten Hopp 514794
  		}
Karsten Hopp 514794
  
Karsten Hopp 514794
! 		if (has_state_with_pos(l, state, subs))
Karsten Hopp 514794
! 		    goto skip_add;
Karsten Hopp 514794
  	    }
Karsten Hopp 514794
  
Karsten Hopp 514794
  	    /* when there are backreferences or look-behind matches the number
Karsten Hopp 514794
***************
Karsten Hopp 514794
*** 4600,4605 ****
Karsten Hopp 514794
--- 4635,4681 ----
Karsten Hopp 514794
  		break;
Karsten Hopp 514794
  
Karsten Hopp 514794
  	    case NFA_START_PATTERN:
Karsten Hopp 514794
+ 	      {
Karsten Hopp 514794
+ 		nfa_state_T *skip = NULL;
Karsten Hopp 514794
+ #ifdef ENABLE_LOG
Karsten Hopp 514794
+ 		int	    skip_lid = 0;
Karsten Hopp 514794
+ #endif
Karsten Hopp 514794
+ 
Karsten Hopp 514794
+ 		/* There is no point in trying to match the pattern if the
Karsten Hopp 514794
+ 		 * output state is not going to be added to the list. */
Karsten Hopp 514794
+ 		if (state_in_list(nextlist, t->state->out1->out, &t->subs))
Karsten Hopp 514794
+ 		{
Karsten Hopp 514794
+ 		    skip = t->state->out1->out;
Karsten Hopp 514794
+ #ifdef ENABLE_LOG
Karsten Hopp 514794
+ 		    skip_lid = nextlist->id;
Karsten Hopp 514794
+ #endif
Karsten Hopp 514794
+ 		}
Karsten Hopp 514794
+ 		else if (state_in_list(nextlist,
Karsten Hopp 514794
+ 					  t->state->out1->out->out, &t->subs))
Karsten Hopp 514794
+ 		{
Karsten Hopp 514794
+ 		    skip = t->state->out1->out->out;
Karsten Hopp 514794
+ #ifdef ENABLE_LOG
Karsten Hopp 514794
+ 		    skip_lid = nextlist->id;
Karsten Hopp 514794
+ #endif
Karsten Hopp 514794
+ 		}
Karsten Hopp 514794
+ 		else if(state_in_list(thislist,
Karsten Hopp 514794
+ 					  t->state->out1->out->out, &t->subs))
Karsten Hopp 514794
+ 		{
Karsten Hopp 514794
+ 		    skip = t->state->out1->out->out;
Karsten Hopp 514794
+ #ifdef ENABLE_LOG
Karsten Hopp 514794
+ 		    skip_lid = thislist->id;
Karsten Hopp 514794
+ #endif
Karsten Hopp 514794
+ 		}
Karsten Hopp 514794
+ 		if (skip != NULL)
Karsten Hopp 514794
+ 		{
Karsten Hopp 514794
+ #ifdef ENABLE_LOG
Karsten Hopp 514794
+ 		    nfa_set_code(skip->c);
Karsten Hopp 514794
+ 		    fprintf(log_fd, "> Not trying to match pattern, output state %d is already in list %d. char %d: %s\n",
Karsten Hopp 514794
+ 			    abs(skip->id), skip_lid, skip->c, code);
Karsten Hopp 514794
+ #endif
Karsten Hopp 514794
+ 		    break;
Karsten Hopp 514794
+ 		}
Karsten Hopp 514794
+ 
Karsten Hopp 514794
  		/* First try matching the pattern. */
Karsten Hopp 514794
  		result = recursive_regmatch(t->state, prog,
Karsten Hopp 514794
  						       submatch, m, &listids);
Karsten Hopp 514794
***************
Karsten Hopp 514794
*** 4654,4659 ****
Karsten Hopp 514794
--- 4730,4736 ----
Karsten Hopp 514794
  		    }
Karsten Hopp 514794
  		}
Karsten Hopp 514794
  		break;
Karsten Hopp 514794
+ 	      }
Karsten Hopp 514794
  
Karsten Hopp 514794
  	    case NFA_BOL:
Karsten Hopp 514794
  		if (reginput == regline)
Karsten Hopp 514794
*** ../vim-7.3.1139/src/version.c	2013-06-07 16:31:45.000000000 +0200
Karsten Hopp 514794
--- src/version.c	2013-06-07 17:30:12.000000000 +0200
Karsten Hopp 514794
***************
Karsten Hopp 514794
*** 730,731 ****
Karsten Hopp 514794
--- 730,733 ----
Karsten Hopp 514794
  {   /* Add new patch number below this line */
Karsten Hopp 514794
+ /**/
Karsten Hopp 514794
+     1140,
Karsten Hopp 514794
  /**/
Karsten Hopp 514794
Karsten Hopp 514794
-- 
Karsten Hopp 514794
From "know your smileys":
Karsten Hopp 514794
 :-*	A big kiss!
Karsten Hopp 514794
Karsten Hopp 514794
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 514794
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 514794
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 514794
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///