Blob Blame History Raw
To: vim_dev@googlegroups.com
Subject: Patch 7.3.1119
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.3.1119
Problem:    Flags in 'cpo' are searched for several times.
Solution:   Store the result and re-use the flags.
Files:	    src/regexp.c, src/regexp_nfa.c


*** ../vim-7.3.1118/src/regexp.c	2013-06-04 21:27:33.000000000 +0200
--- src/regexp.c	2013-06-05 12:37:30.000000000 +0200
***************
*** 365,370 ****
--- 365,371 ----
  static char_u e_z_not_allowed[] = N_("E66: \\z( not allowed here");
  static char_u e_z1_not_allowed[] = N_("E67: \\z1 et al. not allowed here");
  #endif
+ static char_u e_missing_sb[] = N_("E69: Missing ] after %s%%[");
  
  #define NOT_MULTI	0
  #define MULTI_ONE	1
***************
*** 1173,1178 ****
--- 1174,1189 ----
      return 0;
  }
  
+ static void get_cpo_flags __ARGS((void));
+ static int reg_cpo_lit; /* 'cpoptions' contains 'l' flag */
+ static int reg_cpo_bsl; /* 'cpoptions' contains '\' flag */
+ 
+     static void
+ get_cpo_flags()
+ {
+     reg_cpo_lit = vim_strchr(p_cpo, CPO_LITERAL) != NULL;
+     reg_cpo_bsl = vim_strchr(p_cpo, CPO_BACKSL) != NULL;
+ }
  
  /*
   * Skip over a "[]" range.
***************
*** 1183,1197 ****
  skip_anyof(p)
      char_u	*p;
  {
-     int		cpo_lit;	/* 'cpoptions' contains 'l' flag */
-     int		cpo_bsl;	/* 'cpoptions' contains '\' flag */
  #ifdef FEAT_MBYTE
      int		l;
  #endif
  
-     cpo_lit = vim_strchr(p_cpo, CPO_LITERAL) != NULL;
-     cpo_bsl = vim_strchr(p_cpo, CPO_BACKSL) != NULL;
- 
      if (*p == '^')	/* Complement of range. */
  	++p;
      if (*p == ']' || *p == '-')
--- 1194,1203 ----
***************
*** 1210,1218 ****
  		    mb_ptr_adv(p);
  	    }
  	else if (*p == '\\'
! 		&& !cpo_bsl
  		&& (vim_strchr(REGEXP_INRANGE, p[1]) != NULL
! 		    || (!cpo_lit && vim_strchr(REGEXP_ABBR, p[1]) != NULL)))
  	    p += 2;
  	else if (*p == '[')
  	{
--- 1216,1224 ----
  		    mb_ptr_adv(p);
  	    }
  	else if (*p == '\\'
! 		&& !reg_cpo_bsl
  		&& (vim_strchr(REGEXP_INRANGE, p[1]) != NULL
! 		    || (!reg_cpo_lit && vim_strchr(REGEXP_ABBR, p[1]) != NULL)))
  	    p += 2;
  	else if (*p == '[')
  	{
***************
*** 1251,1256 ****
--- 1257,1263 ----
  	mymagic = MAGIC_ON;
      else
  	mymagic = MAGIC_OFF;
+     get_cpo_flags();
  
      for (; p[0] != NUL; mb_ptr_adv(p))
      {
***************
*** 1462,1467 ****
--- 1469,1475 ----
  	reg_magic = MAGIC_OFF;
      reg_string = (re_flags & RE_STRING);
      reg_strict = (re_flags & RE_STRICT);
+     get_cpo_flags();
  
      num_complex_braces = 0;
      regnpar = 1;
***************
*** 1909,1923 ****
  {
      char_u	    *ret;
      int		    flags;
-     int		    cpo_lit;	    /* 'cpoptions' contains 'l' flag */
-     int		    cpo_bsl;	    /* 'cpoptions' contains '\' flag */
      int		    c;
      char_u	    *p;
      int		    extra = 0;
  
      *flagp = WORST;		/* Tentatively. */
-     cpo_lit = vim_strchr(p_cpo, CPO_LITERAL) != NULL;
-     cpo_bsl = vim_strchr(p_cpo, CPO_BACKSL) != NULL;
  
      c = getchr();
      switch (c)
--- 1917,1927 ----
***************
*** 2207,2213 ****
  			      while ((c = getchr()) != ']')
  			      {
  				  if (c == NUL)
! 				      EMSG2_RET_NULL(_("E69: Missing ] after %s%%["),
  						      reg_magic == MAGIC_ALL);
  				  br = regnode(BRANCH);
  				  if (ret == NULL)
--- 2211,2217 ----
  			      while ((c = getchr()) != ']')
  			      {
  				  if (c == NUL)
! 				      EMSG2_RET_NULL(_(e_missing_sb),
  						      reg_magic == MAGIC_ALL);
  				  br = regnode(BRANCH);
  				  if (ret == NULL)
***************
*** 2410,2416 ****
  			    }
  
  			    /* Handle \o40, \x20 and \u20AC style sequences */
! 			    if (endc == '\\' && !cpo_lit && !cpo_bsl)
  				endc = coll_get_char();
  
  			    if (startc > endc)
--- 2414,2420 ----
  			    }
  
  			    /* Handle \o40, \x20 and \u20AC style sequences */
! 			    if (endc == '\\' && !reg_cpo_lit && !reg_cpo_bsl)
  				endc = coll_get_char();
  
  			    if (startc > endc)
***************
*** 2452,2460 ****
  		     * Posix doesn't recognize backslash at all.
  		     */
  		    else if (*regparse == '\\'
! 			    && !cpo_bsl
  			    && (vim_strchr(REGEXP_INRANGE, regparse[1]) != NULL
! 				|| (!cpo_lit
  				    && vim_strchr(REGEXP_ABBR,
  						       regparse[1]) != NULL)))
  		    {
--- 2456,2464 ----
  		     * Posix doesn't recognize backslash at all.
  		     */
  		    else if (*regparse == '\\'
! 			    && !reg_cpo_bsl
  			    && (vim_strchr(REGEXP_INRANGE, regparse[1]) != NULL
! 				|| (!reg_cpo_lit
  				    && vim_strchr(REGEXP_ABBR,
  						       regparse[1]) != NULL)))
  		    {
*** ../vim-7.3.1118/src/regexp_nfa.c	2013-06-05 11:46:22.000000000 +0200
--- src/regexp_nfa.c	2013-06-05 12:38:03.000000000 +0200
***************
*** 686,698 ****
      int		startc = -1;
      int		endc = -1;
      int		oldstartc = -1;
-     int		cpo_lit;	/* 'cpoptions' contains 'l' flag */
-     int		cpo_bsl;	/* 'cpoptions' contains '\' flag */
      int		glue;		/* ID that will "glue" nodes together */
  
-     cpo_lit = vim_strchr(p_cpo, CPO_LITERAL) != NULL;
-     cpo_bsl = vim_strchr(p_cpo, CPO_BACKSL) != NULL;
- 
      c = getchr();
      switch (c)
      {
--- 686,693 ----
***************
*** 1224,1233 ****
  		     * Posix doesn't recognize backslash at all.
  		     */
  		    if (*regparse == '\\'
! 			    && !cpo_bsl
  			    && regparse + 1 <= endp
  			    && (vim_strchr(REGEXP_INRANGE, regparse[1]) != NULL
! 				|| (!cpo_lit
  				    && vim_strchr(REGEXP_ABBR, regparse[1])
  								      != NULL)
  			    )
--- 1219,1228 ----
  		     * Posix doesn't recognize backslash at all.
  		     */
  		    if (*regparse == '\\'
! 			    && !reg_cpo_bsl
  			    && regparse + 1 <= endp
  			    && (vim_strchr(REGEXP_INRANGE, regparse[1]) != NULL
! 				|| (!reg_cpo_lit
  				    && vim_strchr(REGEXP_ABBR, regparse[1])
  								      != NULL)
  			    )
*** ../vim-7.3.1118/src/version.c	2013-06-05 11:46:22.000000000 +0200
--- src/version.c	2013-06-05 12:40:57.000000000 +0200
***************
*** 730,731 ****
--- 730,733 ----
  {   /* Add new patch number below this line */
+ /**/
+     1119,
  /**/

-- 
From "know your smileys":
 :-O>-o   Smiley American tourist (note big mouth and camera)

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///