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