mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:7.4.723
Problem: For indenting, finding the C++ baseclass can be slow.
Solution: Cache the result. (Hirohito Higashi)
4032cfdf17
This commit is contained in:
parent
123361f187
commit
238a8d33fa
@ -17,7 +17,11 @@
|
|||||||
#include "nvim/search.h"
|
#include "nvim/search.h"
|
||||||
#include "nvim/strings.h"
|
#include "nvim/strings.h"
|
||||||
|
|
||||||
|
// Find result cache for cpp_baseclass
|
||||||
|
typedef struct {
|
||||||
|
int found;
|
||||||
|
lpos_T lpos;
|
||||||
|
} cpp_baseclass_cache_T;
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "indent_c.c.generated.h"
|
# include "indent_c.c.generated.h"
|
||||||
@ -986,17 +990,21 @@ static int cin_isbreak(char_u *p)
|
|||||||
*
|
*
|
||||||
* This is a lot of guessing. Watch out for "cond ? func() : foo".
|
* This is a lot of guessing. Watch out for "cond ? func() : foo".
|
||||||
*/
|
*/
|
||||||
static int
|
static int cin_is_cpp_baseclass (
|
||||||
cin_is_cpp_baseclass (
|
cpp_baseclass_cache_T *cached // input and output
|
||||||
colnr_T *col /* return: column to align with */
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
lpos_T *pos = &cached->lpos; // find position
|
||||||
char_u *s;
|
char_u *s;
|
||||||
int class_or_struct, lookfor_ctor_init, cpp_base_class;
|
int class_or_struct, lookfor_ctor_init, cpp_base_class;
|
||||||
linenr_T lnum = curwin->w_cursor.lnum;
|
linenr_T lnum = curwin->w_cursor.lnum;
|
||||||
char_u *line = get_cursor_line_ptr();
|
char_u *line = get_cursor_line_ptr();
|
||||||
|
|
||||||
*col = 0;
|
if (pos->lnum <= lnum) {
|
||||||
|
return cached->found; // Use the cached result
|
||||||
|
}
|
||||||
|
|
||||||
|
pos->col = 0;
|
||||||
|
|
||||||
s = skipwhite(line);
|
s = skipwhite(line);
|
||||||
if (*s == '#') /* skip #define FOO x ? (x) : x */
|
if (*s == '#') /* skip #define FOO x ? (x) : x */
|
||||||
@ -1038,6 +1046,7 @@ cin_is_cpp_baseclass (
|
|||||||
--lnum;
|
--lnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pos->lnum = lnum;
|
||||||
line = ml_get(lnum);
|
line = ml_get(lnum);
|
||||||
s = cin_skipcomment(line);
|
s = cin_skipcomment(line);
|
||||||
for (;; ) {
|
for (;; ) {
|
||||||
@ -1064,7 +1073,7 @@ cin_is_cpp_baseclass (
|
|||||||
* cpp-base-class-declaration or constructor-initialization */
|
* cpp-base-class-declaration or constructor-initialization */
|
||||||
cpp_base_class = TRUE;
|
cpp_base_class = TRUE;
|
||||||
lookfor_ctor_init = class_or_struct = FALSE;
|
lookfor_ctor_init = class_or_struct = FALSE;
|
||||||
*col = 0;
|
pos->col = 0;
|
||||||
s = cin_skipcomment(s + 1);
|
s = cin_skipcomment(s + 1);
|
||||||
} else
|
} else
|
||||||
s = cin_skipcomment(s + 1);
|
s = cin_skipcomment(s + 1);
|
||||||
@ -1092,23 +1101,29 @@ cin_is_cpp_baseclass (
|
|||||||
/* if it is not an identifier, we are wrong */
|
/* if it is not an identifier, we are wrong */
|
||||||
class_or_struct = FALSE;
|
class_or_struct = FALSE;
|
||||||
lookfor_ctor_init = FALSE;
|
lookfor_ctor_init = FALSE;
|
||||||
} else if (*col == 0) {
|
} else if (pos->col == 0) {
|
||||||
/* it can't be a constructor-initialization any more */
|
/* it can't be a constructor-initialization any more */
|
||||||
lookfor_ctor_init = FALSE;
|
lookfor_ctor_init = FALSE;
|
||||||
|
|
||||||
/* the first statement starts here: lineup with this one... */
|
/* the first statement starts here: lineup with this one... */
|
||||||
if (cpp_base_class)
|
if (cpp_base_class) {
|
||||||
*col = (colnr_T)(s - line);
|
pos->col = (colnr_T)(s - line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* When the line ends in a comma don't align with it. */
|
/* When the line ends in a comma don't align with it. */
|
||||||
if (lnum == curwin->w_cursor.lnum && *s == ',' && cin_nocode(s + 1))
|
if (lnum == curwin->w_cursor.lnum && *s == ',' && cin_nocode(s + 1)) {
|
||||||
*col = 0;
|
pos->col = 0;
|
||||||
|
}
|
||||||
|
|
||||||
s = cin_skipcomment(s + 1);
|
s = cin_skipcomment(s + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cached->found = cpp_base_class;
|
||||||
|
if (cpp_base_class) {
|
||||||
|
pos->lnum = lnum;
|
||||||
|
}
|
||||||
return cpp_base_class;
|
return cpp_base_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1596,6 +1611,7 @@ int get_c_indent(void)
|
|||||||
int cont_amount = 0; /* amount for continuation line */
|
int cont_amount = 0; /* amount for continuation line */
|
||||||
int original_line_islabel;
|
int original_line_islabel;
|
||||||
int added_to_amount = 0;
|
int added_to_amount = 0;
|
||||||
|
cpp_baseclass_cache_T cache_cpp_baseclass = { false, { MAXLNUM, 0 } };
|
||||||
|
|
||||||
/* make a copy, value is changed below */
|
/* make a copy, value is changed below */
|
||||||
int ind_continuation = curbuf->b_ind_continuation;
|
int ind_continuation = curbuf->b_ind_continuation;
|
||||||
@ -2511,7 +2527,7 @@ int get_c_indent(void)
|
|||||||
*/ /* XXX */
|
*/ /* XXX */
|
||||||
n = FALSE;
|
n = FALSE;
|
||||||
if (lookfor != LOOKFOR_TERM && curbuf->b_ind_cpp_baseclass > 0) {
|
if (lookfor != LOOKFOR_TERM && curbuf->b_ind_cpp_baseclass > 0) {
|
||||||
n = cin_is_cpp_baseclass(&col);
|
n = cin_is_cpp_baseclass(&cache_cpp_baseclass);
|
||||||
l = get_cursor_line_ptr();
|
l = get_cursor_line_ptr();
|
||||||
}
|
}
|
||||||
if (n) {
|
if (n) {
|
||||||
@ -2527,7 +2543,7 @@ int get_c_indent(void)
|
|||||||
continue;
|
continue;
|
||||||
} else
|
} else
|
||||||
/* XXX */
|
/* XXX */
|
||||||
amount = get_baseclass_amount(col);
|
amount = get_baseclass_amount(cache_cpp_baseclass.lpos.col);
|
||||||
break;
|
break;
|
||||||
} else if (lookfor == LOOKFOR_CPP_BASECLASS) {
|
} else if (lookfor == LOOKFOR_CPP_BASECLASS) {
|
||||||
/* only look, whether there is a cpp base class
|
/* only look, whether there is a cpp base class
|
||||||
@ -3132,12 +3148,12 @@ term_again:
|
|||||||
*/ /* XXX */
|
*/ /* XXX */
|
||||||
n = FALSE;
|
n = FALSE;
|
||||||
if (curbuf->b_ind_cpp_baseclass != 0 && theline[0] != '{') {
|
if (curbuf->b_ind_cpp_baseclass != 0 && theline[0] != '{') {
|
||||||
n = cin_is_cpp_baseclass(&col);
|
n = cin_is_cpp_baseclass(&cache_cpp_baseclass);
|
||||||
l = get_cursor_line_ptr();
|
l = get_cursor_line_ptr();
|
||||||
}
|
}
|
||||||
if (n) {
|
if (n) {
|
||||||
/* XXX */
|
/* XXX */
|
||||||
amount = get_baseclass_amount(col);
|
amount = get_baseclass_amount(cache_cpp_baseclass.lpos.col);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ static int included_patches[] = {
|
|||||||
// 726 NA
|
// 726 NA
|
||||||
// 725,
|
// 725,
|
||||||
// 724 NA
|
// 724 NA
|
||||||
// 723,
|
723,
|
||||||
// 722,
|
// 722,
|
||||||
// 721,
|
// 721,
|
||||||
// 720 NA
|
// 720 NA
|
||||||
|
Loading…
Reference in New Issue
Block a user