Patch 7.4.723
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 intcin_is_if_for_while_before_offset __ARGS((char_u *line, int *poffset)); static intcin_iswhileofdo_end __ARGS((int terminated)); static intcin_isbreak __ARGS((char_u *)); ! static intcin_is_cpp_baseclass __ARGS((colnr_T *col)); static intget_baseclass_amount __ARGS((int col)); static intcin_ends_in __ARGS((char_u *, char_u *, char_u *)); static intcin_starts_with __ARGS((char_u *s, char *word)); --- 5415,5421 static intcin_is_if_for_while_before_offset __ARGS((char_u *line, int *poffset)); static intcin_iswhileofdo_end __ARGS((int terminated)); static intcin_isbreak __ARGS((char_u *)); ! static intcin_is_cpp_baseclass __ARGS((cpp_baseclass_cache_T *cached)); static intget_baseclass_amount __ARGS((int col)); static intcin_ends_in __ARGS((char_u *, char_u *, char_u *)); static intcin_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
Patch 7.4.723
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 intcin_is_if_for_while_before_offset __ARGS((char_u *line, int *poffset)); static intcin_iswhileofdo_end __ARGS((int terminated)); static intcin_isbreak __ARGS((char_u *)); ! static intcin_is_cpp_baseclass __ARGS((colnr_T *col)); static intget_baseclass_amount __ARGS((int col)); static intcin_ends_in __ARGS((char_u *, char_u *, char_u *)); static intcin_starts_with __ARGS((char_u *s, char *word)); --- 5415,5421 static intcin_is_if_for_while_before_offset __ARGS((char_u *line, int *poffset)); static intcin_iswhileofdo_end __ARGS((int terminated)); static intcin_isbreak __ARGS((char_u *)); ! static intcin_is_cpp_baseclass __ARGS((cpp_baseclass_cache_T *cached)); static intget_baseclass_amount __ARGS((int col)); static intcin_ends_in __ARGS((char_u *, char_u *, char_u *)); static intcin_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