Karsten Hopp a3094a
To: vim_dev@googlegroups.com
Karsten Hopp a3094a
Subject: Patch 7.4.723
Karsten Hopp a3094a
Fcc: outbox
Karsten Hopp a3094a
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp a3094a
Mime-Version: 1.0
Karsten Hopp a3094a
Content-Type: text/plain; charset=UTF-8
Karsten Hopp a3094a
Content-Transfer-Encoding: 8bit
Karsten Hopp a3094a
------------
Karsten Hopp a3094a
Karsten Hopp a3094a
Patch 7.4.723
Karsten Hopp a3094a
Problem:    For indenting, finding the C++ baseclass can be slow.
Karsten Hopp a3094a
Solution:   Cache the result. (Hirohito Higashi)
Karsten Hopp a3094a
Files:      src/misc1.c
Karsten Hopp a3094a
Karsten Hopp a3094a
Karsten Hopp a3094a
*** ../vim-7.4.722/src/misc1.c	2015-03-31 13:33:00.797524914 +0200
Karsten Hopp a3094a
--- src/misc1.c	2015-05-04 17:45:41.108783310 +0200
Karsten Hopp a3094a
***************
Karsten Hopp a3094a
*** 5376,5381 ****
Karsten Hopp a3094a
--- 5376,5387 ----
Karsten Hopp a3094a
  	fixthisline(get_c_indent);
Karsten Hopp a3094a
  }
Karsten Hopp a3094a
  
Karsten Hopp a3094a
+ /* Find result cache for cpp_baseclass */
Karsten Hopp a3094a
+ typedef struct {
Karsten Hopp a3094a
+     int	    found;
Karsten Hopp a3094a
+     lpos_T  lpos;
Karsten Hopp a3094a
+ } cpp_baseclass_cache_T;
Karsten Hopp a3094a
+ 
Karsten Hopp a3094a
  /*
Karsten Hopp a3094a
   * Functions for C-indenting.
Karsten Hopp a3094a
   * Most of this originally comes from Eric Fischer.
Karsten Hopp a3094a
***************
Karsten Hopp a3094a
*** 5409,5415 ****
Karsten Hopp a3094a
  static int	cin_is_if_for_while_before_offset __ARGS((char_u *line, int *poffset));
Karsten Hopp a3094a
  static int	cin_iswhileofdo_end __ARGS((int terminated));
Karsten Hopp a3094a
  static int	cin_isbreak __ARGS((char_u *));
Karsten Hopp a3094a
! static int	cin_is_cpp_baseclass __ARGS((colnr_T *col));
Karsten Hopp a3094a
  static int	get_baseclass_amount __ARGS((int col));
Karsten Hopp a3094a
  static int	cin_ends_in __ARGS((char_u *, char_u *, char_u *));
Karsten Hopp a3094a
  static int	cin_starts_with __ARGS((char_u *s, char *word));
Karsten Hopp a3094a
--- 5415,5421 ----
Karsten Hopp a3094a
  static int	cin_is_if_for_while_before_offset __ARGS((char_u *line, int *poffset));
Karsten Hopp a3094a
  static int	cin_iswhileofdo_end __ARGS((int terminated));
Karsten Hopp a3094a
  static int	cin_isbreak __ARGS((char_u *));
Karsten Hopp a3094a
! static int	cin_is_cpp_baseclass __ARGS((cpp_baseclass_cache_T *cached));
Karsten Hopp a3094a
  static int	get_baseclass_amount __ARGS((int col));
Karsten Hopp a3094a
  static int	cin_ends_in __ARGS((char_u *, char_u *, char_u *));
Karsten Hopp a3094a
  static int	cin_starts_with __ARGS((char_u *s, char *word));
Karsten Hopp a3094a
***************
Karsten Hopp a3094a
*** 6372,6386 ****
Karsten Hopp a3094a
   * This is a lot of guessing.  Watch out for "cond ? func() : foo".
Karsten Hopp a3094a
   */
Karsten Hopp a3094a
      static int
Karsten Hopp a3094a
! cin_is_cpp_baseclass(col)
Karsten Hopp a3094a
!     colnr_T	*col;	    /* return: column to align with */
Karsten Hopp a3094a
  {
Karsten Hopp a3094a
      char_u	*s;
Karsten Hopp a3094a
      int		class_or_struct, lookfor_ctor_init, cpp_base_class;
Karsten Hopp a3094a
      linenr_T	lnum = curwin->w_cursor.lnum;
Karsten Hopp a3094a
      char_u	*line = ml_get_curline();
Karsten Hopp a3094a
  
Karsten Hopp a3094a
!     *col = 0;
Karsten Hopp a3094a
  
Karsten Hopp a3094a
      s = skipwhite(line);
Karsten Hopp a3094a
      if (*s == '#')		/* skip #define FOO x ? (x) : x */
Karsten Hopp a3094a
--- 6378,6396 ----
Karsten Hopp a3094a
   * This is a lot of guessing.  Watch out for "cond ? func() : foo".
Karsten Hopp a3094a
   */
Karsten Hopp a3094a
      static int
Karsten Hopp a3094a
! cin_is_cpp_baseclass(cached)
Karsten Hopp a3094a
!     cpp_baseclass_cache_T *cached; /* input and output */
Karsten Hopp a3094a
  {
Karsten Hopp a3094a
+     lpos_T	*pos = &cached->lpos;	    /* find position */
Karsten Hopp a3094a
      char_u	*s;
Karsten Hopp a3094a
      int		class_or_struct, lookfor_ctor_init, cpp_base_class;
Karsten Hopp a3094a
      linenr_T	lnum = curwin->w_cursor.lnum;
Karsten Hopp a3094a
      char_u	*line = ml_get_curline();
Karsten Hopp a3094a
  
Karsten Hopp a3094a
!     if (pos->lnum <= lnum)
Karsten Hopp a3094a
! 	return cached->found;	/* Use the cached result */
Karsten Hopp a3094a
! 
Karsten Hopp a3094a
!     pos->col = 0;
Karsten Hopp a3094a
  
Karsten Hopp a3094a
      s = skipwhite(line);
Karsten Hopp a3094a
      if (*s == '#')		/* skip #define FOO x ? (x) : x */
Karsten Hopp a3094a
***************
Karsten Hopp a3094a
*** 6424,6429 ****
Karsten Hopp a3094a
--- 6434,6440 ----
Karsten Hopp a3094a
  	--lnum;
Karsten Hopp a3094a
      }
Karsten Hopp a3094a
  
Karsten Hopp a3094a
+     pos->lnum = lnum;
Karsten Hopp a3094a
      line = ml_get(lnum);
Karsten Hopp a3094a
      s = cin_skipcomment(line);
Karsten Hopp a3094a
      for (;;)
Karsten Hopp a3094a
***************
Karsten Hopp a3094a
*** 6456,6462 ****
Karsten Hopp a3094a
  		 * cpp-base-class-declaration or constructor-initialization */
Karsten Hopp a3094a
  		cpp_base_class = TRUE;
Karsten Hopp a3094a
  		lookfor_ctor_init = class_or_struct = FALSE;
Karsten Hopp a3094a
! 		*col = 0;
Karsten Hopp a3094a
  		s = cin_skipcomment(s + 1);
Karsten Hopp a3094a
  	    }
Karsten Hopp a3094a
  	    else
Karsten Hopp a3094a
--- 6467,6473 ----
Karsten Hopp a3094a
  		 * cpp-base-class-declaration or constructor-initialization */
Karsten Hopp a3094a
  		cpp_base_class = TRUE;
Karsten Hopp a3094a
  		lookfor_ctor_init = class_or_struct = FALSE;
Karsten Hopp a3094a
! 		pos->col = 0;
Karsten Hopp a3094a
  		s = cin_skipcomment(s + 1);
Karsten Hopp a3094a
  	    }
Karsten Hopp a3094a
  	    else
Karsten Hopp a3094a
***************
Karsten Hopp a3094a
*** 6497,6520 ****
Karsten Hopp a3094a
  		class_or_struct = FALSE;
Karsten Hopp a3094a
  		lookfor_ctor_init = FALSE;
Karsten Hopp a3094a
  	    }
Karsten Hopp a3094a
! 	    else if (*col == 0)
Karsten Hopp a3094a
  	    {
Karsten Hopp a3094a
  		/* it can't be a constructor-initialization any more */
Karsten Hopp a3094a
  		lookfor_ctor_init = FALSE;
Karsten Hopp a3094a
  
Karsten Hopp a3094a
  		/* the first statement starts here: lineup with this one... */
Karsten Hopp a3094a
  		if (cpp_base_class)
Karsten Hopp a3094a
! 		    *col = (colnr_T)(s - line);
Karsten Hopp a3094a
  	    }
Karsten Hopp a3094a
  
Karsten Hopp a3094a
  	    /* When the line ends in a comma don't align with it. */
Karsten Hopp a3094a
  	    if (lnum == curwin->w_cursor.lnum && *s == ',' && cin_nocode(s + 1))
Karsten Hopp a3094a
! 		*col = 0;
Karsten Hopp a3094a
  
Karsten Hopp a3094a
  	    s = cin_skipcomment(s + 1);
Karsten Hopp a3094a
  	}
Karsten Hopp a3094a
      }
Karsten Hopp a3094a
  
Karsten Hopp a3094a
      return cpp_base_class;
Karsten Hopp a3094a
  }
Karsten Hopp a3094a
  
Karsten Hopp a3094a
--- 6508,6534 ----
Karsten Hopp a3094a
  		class_or_struct = FALSE;
Karsten Hopp a3094a
  		lookfor_ctor_init = FALSE;
Karsten Hopp a3094a
  	    }
Karsten Hopp a3094a
! 	    else if (pos->col == 0)
Karsten Hopp a3094a
  	    {
Karsten Hopp a3094a
  		/* it can't be a constructor-initialization any more */
Karsten Hopp a3094a
  		lookfor_ctor_init = FALSE;
Karsten Hopp a3094a
  
Karsten Hopp a3094a
  		/* the first statement starts here: lineup with this one... */
Karsten Hopp a3094a
  		if (cpp_base_class)
Karsten Hopp a3094a
! 		    pos->col = (colnr_T)(s - line);
Karsten Hopp a3094a
  	    }
Karsten Hopp a3094a
  
Karsten Hopp a3094a
  	    /* When the line ends in a comma don't align with it. */
Karsten Hopp a3094a
  	    if (lnum == curwin->w_cursor.lnum && *s == ',' && cin_nocode(s + 1))
Karsten Hopp a3094a
! 		pos->col = 0;
Karsten Hopp a3094a
  
Karsten Hopp a3094a
  	    s = cin_skipcomment(s + 1);
Karsten Hopp a3094a
  	}
Karsten Hopp a3094a
      }
Karsten Hopp a3094a
  
Karsten Hopp a3094a
+     cached->found = cpp_base_class;
Karsten Hopp a3094a
+     if (cpp_base_class)
Karsten Hopp a3094a
+ 	pos->lnum = lnum;
Karsten Hopp a3094a
      return cpp_base_class;
Karsten Hopp a3094a
  }
Karsten Hopp a3094a
  
Karsten Hopp a3094a
***************
Karsten Hopp a3094a
*** 7047,7053 ****
Karsten Hopp a3094a
  #define LOOKFOR_CPP_BASECLASS	9
Karsten Hopp a3094a
  #define LOOKFOR_ENUM_OR_INIT	10
Karsten Hopp a3094a
  #define LOOKFOR_JS_KEY		11
Karsten Hopp a3094a
! #define LOOKFOR_COMMA	12
Karsten Hopp a3094a
  
Karsten Hopp a3094a
      int		whilelevel;
Karsten Hopp a3094a
      linenr_T	lnum;
Karsten Hopp a3094a
--- 7061,7067 ----
Karsten Hopp a3094a
  #define LOOKFOR_CPP_BASECLASS	9
Karsten Hopp a3094a
  #define LOOKFOR_ENUM_OR_INIT	10
Karsten Hopp a3094a
  #define LOOKFOR_JS_KEY		11
Karsten Hopp a3094a
! #define LOOKFOR_COMMA		12
Karsten Hopp a3094a
  
Karsten Hopp a3094a
      int		whilelevel;
Karsten Hopp a3094a
      linenr_T	lnum;
Karsten Hopp a3094a
***************
Karsten Hopp a3094a
*** 7059,7064 ****
Karsten Hopp a3094a
--- 7073,7079 ----
Karsten Hopp a3094a
      int		original_line_islabel;
Karsten Hopp a3094a
      int		added_to_amount = 0;
Karsten Hopp a3094a
      int		js_cur_has_key = 0;
Karsten Hopp a3094a
+     cpp_baseclass_cache_T cache_cpp_baseclass = { FALSE, { MAXLNUM, 0 } };
Karsten Hopp a3094a
  
Karsten Hopp a3094a
      /* make a copy, value is changed below */
Karsten Hopp a3094a
      int		ind_continuation = curbuf->b_ind_continuation;
Karsten Hopp a3094a
***************
Karsten Hopp a3094a
*** 8089,8095 ****
Karsten Hopp a3094a
  		n = FALSE;
Karsten Hopp a3094a
  		if (lookfor != LOOKFOR_TERM && curbuf->b_ind_cpp_baseclass > 0)
Karsten Hopp a3094a
  		{
Karsten Hopp a3094a
! 		    n = cin_is_cpp_baseclass(&col);
Karsten Hopp a3094a
  		    l = ml_get_curline();
Karsten Hopp a3094a
  		}
Karsten Hopp a3094a
  		if (n)
Karsten Hopp a3094a
--- 8104,8110 ----
Karsten Hopp a3094a
  		n = FALSE;
Karsten Hopp a3094a
  		if (lookfor != LOOKFOR_TERM && curbuf->b_ind_cpp_baseclass > 0)
Karsten Hopp a3094a
  		{
Karsten Hopp a3094a
! 		    n = cin_is_cpp_baseclass(&cache_cpp_baseclass);
Karsten Hopp a3094a
  		    l = ml_get_curline();
Karsten Hopp a3094a
  		}
Karsten Hopp a3094a
  		if (n)
Karsten Hopp a3094a
***************
Karsten Hopp a3094a
*** 8110,8116 ****
Karsten Hopp a3094a
  		    }
Karsten Hopp a3094a
  		    else
Karsten Hopp a3094a
  								     /* XXX */
Karsten Hopp a3094a
! 			amount = get_baseclass_amount(col);
Karsten Hopp a3094a
  		    break;
Karsten Hopp a3094a
  		}
Karsten Hopp a3094a
  		else if (lookfor == LOOKFOR_CPP_BASECLASS)
Karsten Hopp a3094a
--- 8125,8132 ----
Karsten Hopp a3094a
  		    }
Karsten Hopp a3094a
  		    else
Karsten Hopp a3094a
  								     /* XXX */
Karsten Hopp a3094a
! 			amount = get_baseclass_amount(
Karsten Hopp a3094a
! 						cache_cpp_baseclass.lpos.col);
Karsten Hopp a3094a
  		    break;
Karsten Hopp a3094a
  		}
Karsten Hopp a3094a
  		else if (lookfor == LOOKFOR_CPP_BASECLASS)
Karsten Hopp a3094a
***************
Karsten Hopp a3094a
*** 8780,8792 ****
Karsten Hopp a3094a
  		n = FALSE;
Karsten Hopp a3094a
  		if (curbuf->b_ind_cpp_baseclass != 0 && theline[0] != '{')
Karsten Hopp a3094a
  		{
Karsten Hopp a3094a
! 		    n = cin_is_cpp_baseclass(&col);
Karsten Hopp a3094a
  		    l = ml_get_curline();
Karsten Hopp a3094a
  		}
Karsten Hopp a3094a
  		if (n)
Karsten Hopp a3094a
  		{
Karsten Hopp a3094a
  								     /* XXX */
Karsten Hopp a3094a
! 		    amount = get_baseclass_amount(col);
Karsten Hopp a3094a
  		    break;
Karsten Hopp a3094a
  		}
Karsten Hopp a3094a
  
Karsten Hopp a3094a
--- 8796,8808 ----
Karsten Hopp a3094a
  		n = FALSE;
Karsten Hopp a3094a
  		if (curbuf->b_ind_cpp_baseclass != 0 && theline[0] != '{')
Karsten Hopp a3094a
  		{
Karsten Hopp a3094a
! 		    n = cin_is_cpp_baseclass(&cache_cpp_baseclass);
Karsten Hopp a3094a
  		    l = ml_get_curline();
Karsten Hopp a3094a
  		}
Karsten Hopp a3094a
  		if (n)
Karsten Hopp a3094a
  		{
Karsten Hopp a3094a
  								     /* XXX */
Karsten Hopp a3094a
! 		    amount = get_baseclass_amount(cache_cpp_baseclass.lpos.col);
Karsten Hopp a3094a
  		    break;
Karsten Hopp a3094a
  		}
Karsten Hopp a3094a
  
Karsten Hopp a3094a
*** ../vim-7.4.722/src/version.c	2015-05-04 17:28:17.344445737 +0200
Karsten Hopp a3094a
--- src/version.c	2015-05-04 17:30:58.030650914 +0200
Karsten Hopp a3094a
***************
Karsten Hopp a3094a
*** 743,744 ****
Karsten Hopp a3094a
--- 743,746 ----
Karsten Hopp a3094a
  {   /* Add new patch number below this line */
Karsten Hopp a3094a
+ /**/
Karsten Hopp a3094a
+     723,
Karsten Hopp a3094a
  /**/
Karsten Hopp a3094a
Karsten Hopp a3094a
-- 
Karsten Hopp a3094a
I have a drinking problem -- I don't have a drink!
Karsten Hopp a3094a
Karsten Hopp a3094a
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp a3094a
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp a3094a
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp a3094a
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///