Karsten Hopp aa0805
To: vim_dev@googlegroups.com
Karsten Hopp aa0805
Subject: Patch 7.3.1145
Karsten Hopp aa0805
Fcc: outbox
Karsten Hopp aa0805
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp aa0805
Mime-Version: 1.0
Karsten Hopp aa0805
Content-Type: text/plain; charset=UTF-8
Karsten Hopp aa0805
Content-Transfer-Encoding: 8bit
Karsten Hopp aa0805
------------
Karsten Hopp aa0805
Karsten Hopp aa0805
Patch 7.3.1145
Karsten Hopp aa0805
Problem:    New regexp engine: addstate() is called very often.
Karsten Hopp aa0805
Solution:   Optimize adding the start state.
Karsten Hopp aa0805
Files:	    src/regexp_nfa.c
Karsten Hopp aa0805
Karsten Hopp aa0805
Karsten Hopp aa0805
*** ../vim-7.3.1144/src/regexp_nfa.c	2013-06-07 17:31:25.000000000 +0200
Karsten Hopp aa0805
--- src/regexp_nfa.c	2013-06-07 22:03:12.000000000 +0200
Karsten Hopp aa0805
***************
Karsten Hopp aa0805
*** 4332,4340 ****
Karsten Hopp aa0805
      nfa_list_T	*nextlist;
Karsten Hopp aa0805
      int		*listids = NULL;
Karsten Hopp aa0805
      nfa_state_T *add_state;
Karsten Hopp aa0805
!     int		 add_count;
Karsten Hopp aa0805
!     int		 add_off;
Karsten Hopp aa0805
      garray_T	pimlist;
Karsten Hopp aa0805
  #ifdef NFA_REGEXP_DEBUG_LOG
Karsten Hopp aa0805
      FILE	*debug = fopen(NFA_REGEXP_DEBUG_LOG, "a");
Karsten Hopp aa0805
  
Karsten Hopp aa0805
--- 4332,4341 ----
Karsten Hopp aa0805
      nfa_list_T	*nextlist;
Karsten Hopp aa0805
      int		*listids = NULL;
Karsten Hopp aa0805
      nfa_state_T *add_state;
Karsten Hopp aa0805
!     int		add_count;
Karsten Hopp aa0805
!     int		add_off;
Karsten Hopp aa0805
      garray_T	pimlist;
Karsten Hopp aa0805
+     int		toplevel = start->c == NFA_MOPEN;
Karsten Hopp aa0805
  #ifdef NFA_REGEXP_DEBUG_LOG
Karsten Hopp aa0805
      FILE	*debug = fopen(NFA_REGEXP_DEBUG_LOG, "a");
Karsten Hopp aa0805
  
Karsten Hopp aa0805
***************
Karsten Hopp aa0805
*** 4378,4387 ****
Karsten Hopp aa0805
      nextlist = &list[1];
Karsten Hopp aa0805
      nextlist->n = 0;
Karsten Hopp aa0805
  #ifdef ENABLE_LOG
Karsten Hopp aa0805
!     fprintf(log_fd, "(---) STARTSTATE\n");
Karsten Hopp aa0805
  #endif
Karsten Hopp aa0805
      thislist->id = nfa_listid + 1;
Karsten Hopp aa0805
!     addstate(thislist, start, m, 0);
Karsten Hopp aa0805
  
Karsten Hopp aa0805
  #define	ADD_STATE_IF_MATCH(state)			\
Karsten Hopp aa0805
      if (result) {					\
Karsten Hopp aa0805
--- 4379,4404 ----
Karsten Hopp aa0805
      nextlist = &list[1];
Karsten Hopp aa0805
      nextlist->n = 0;
Karsten Hopp aa0805
  #ifdef ENABLE_LOG
Karsten Hopp aa0805
!     fprintf(log_fd, "(---) STARTSTATE first\n");
Karsten Hopp aa0805
  #endif
Karsten Hopp aa0805
      thislist->id = nfa_listid + 1;
Karsten Hopp aa0805
! 
Karsten Hopp aa0805
!     /* Inline optimized code for addstate(thislist, start, m, 0) if we know
Karsten Hopp aa0805
!      * it's the first MOPEN. */
Karsten Hopp aa0805
!     if (toplevel)
Karsten Hopp aa0805
!     {
Karsten Hopp aa0805
! 	if (REG_MULTI)
Karsten Hopp aa0805
! 	{
Karsten Hopp aa0805
! 	    m->norm.list.multi[0].start.lnum = reglnum;
Karsten Hopp aa0805
! 	    m->norm.list.multi[0].start.col = (colnr_T)(reginput - regline);
Karsten Hopp aa0805
! 	}
Karsten Hopp aa0805
! 	else
Karsten Hopp aa0805
! 	    m->norm.list.line[0].start = reginput;
Karsten Hopp aa0805
! 	m->norm.in_use = 1;
Karsten Hopp aa0805
! 	addstate(thislist, start->out, m, 0);
Karsten Hopp aa0805
!     }
Karsten Hopp aa0805
!     else
Karsten Hopp aa0805
! 	addstate(thislist, start, m, 0);
Karsten Hopp aa0805
  
Karsten Hopp aa0805
  #define	ADD_STATE_IF_MATCH(state)			\
Karsten Hopp aa0805
      if (result) {					\
Karsten Hopp aa0805
***************
Karsten Hopp aa0805
*** 5382,5388 ****
Karsten Hopp aa0805
  	 * Unless "nfa_endp" is not NULL, then we match the end position.
Karsten Hopp aa0805
  	 * Also don't start a match past the first line. */
Karsten Hopp aa0805
  	if (nfa_match == FALSE
Karsten Hopp aa0805
! 		&& ((start->c == NFA_MOPEN
Karsten Hopp aa0805
  			&& reglnum == 0
Karsten Hopp aa0805
  			&& clen != 0
Karsten Hopp aa0805
  			&& (ireg_maxcol == 0
Karsten Hopp aa0805
--- 5399,5405 ----
Karsten Hopp aa0805
  	 * Unless "nfa_endp" is not NULL, then we match the end position.
Karsten Hopp aa0805
  	 * Also don't start a match past the first line. */
Karsten Hopp aa0805
  	if (nfa_match == FALSE
Karsten Hopp aa0805
! 		&& ((toplevel
Karsten Hopp aa0805
  			&& reglnum == 0
Karsten Hopp aa0805
  			&& clen != 0
Karsten Hopp aa0805
  			&& (ireg_maxcol == 0
Karsten Hopp aa0805
***************
Karsten Hopp aa0805
*** 5398,5404 ****
Karsten Hopp aa0805
  #ifdef ENABLE_LOG
Karsten Hopp aa0805
  	    fprintf(log_fd, "(---) STARTSTATE\n");
Karsten Hopp aa0805
  #endif
Karsten Hopp aa0805
! 	    addstate(nextlist, start, m, clen);
Karsten Hopp aa0805
  	}
Karsten Hopp aa0805
  
Karsten Hopp aa0805
  #ifdef ENABLE_LOG
Karsten Hopp aa0805
--- 5415,5433 ----
Karsten Hopp aa0805
  #ifdef ENABLE_LOG
Karsten Hopp aa0805
  	    fprintf(log_fd, "(---) STARTSTATE\n");
Karsten Hopp aa0805
  #endif
Karsten Hopp aa0805
! 	    /* Inline optimized code for addstate() if we know the state is
Karsten Hopp aa0805
! 	     * the first MOPEN. */
Karsten Hopp aa0805
! 	    if (toplevel)
Karsten Hopp aa0805
! 	    {
Karsten Hopp aa0805
! 		if (REG_MULTI)
Karsten Hopp aa0805
! 		    m->norm.list.multi[0].start.col =
Karsten Hopp aa0805
! 					 (colnr_T)(reginput - regline) + clen;
Karsten Hopp aa0805
! 		else
Karsten Hopp aa0805
! 		    m->norm.list.line[0].start = reginput + clen;
Karsten Hopp aa0805
! 		addstate(nextlist, start->out, m, clen);
Karsten Hopp aa0805
! 	    }
Karsten Hopp aa0805
! 	    else
Karsten Hopp aa0805
! 		addstate(nextlist, start, m, clen);
Karsten Hopp aa0805
  	}
Karsten Hopp aa0805
  
Karsten Hopp aa0805
  #ifdef ENABLE_LOG
Karsten Hopp aa0805
*** ../vim-7.3.1144/src/version.c	2013-06-07 20:17:06.000000000 +0200
Karsten Hopp aa0805
--- src/version.c	2013-06-07 22:37:03.000000000 +0200
Karsten Hopp aa0805
***************
Karsten Hopp aa0805
*** 730,731 ****
Karsten Hopp aa0805
--- 730,733 ----
Karsten Hopp aa0805
  {   /* Add new patch number below this line */
Karsten Hopp aa0805
+ /**/
Karsten Hopp aa0805
+     1145,
Karsten Hopp aa0805
  /**/
Karsten Hopp aa0805
Karsten Hopp aa0805
-- 
Karsten Hopp aa0805
hundred-and-one symptoms of being an internet addict:
Karsten Hopp aa0805
104. When people ask about the Presidential Election you ask "Which country?"
Karsten Hopp aa0805
Karsten Hopp aa0805
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp aa0805
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp aa0805
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp aa0805
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///