0
0
mirror of https://github.com/vim/vim.git synced 2025-08-25 19:53:53 -04:00

patch 9.1.1328: too many strlen() calls in indent.c

Problem:  too many strlen() calls in indent.c
Solution: refactor indent.c slightly and remove strlen() calls
          (John Marriott)

closes: #17156

Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
John Marriott 2025-04-21 11:01:53 +02:00 committed by Christian Brabandt
parent 2cb42efc18
commit eac45c558e
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
2 changed files with 12 additions and 7 deletions

View File

@ -524,7 +524,7 @@ set_indent(
char_u *s; char_u *s;
int todo; int todo;
int ind_len; // measured in characters int ind_len; // measured in characters
int line_len; int line_len; // size of the line (including the NUL)
int doit = FALSE; int doit = FALSE;
int ind_done = 0; // measured in spaces int ind_done = 0; // measured in spaces
#ifdef FEAT_VARTABS #ifdef FEAT_VARTABS
@ -540,6 +540,7 @@ set_indent(
todo = size; todo = size;
ind_len = 0; ind_len = 0;
p = oldline = ml_get_curline(); p = oldline = ml_get_curline();
line_len = ml_get_curline_len() + 1;
// Calculate the buffer size for the new indent, and check to see if it // Calculate the buffer size for the new indent, and check to see if it
// isn't already set // isn't already set
@ -660,8 +661,10 @@ set_indent(
if (flags & SIN_INSERT) if (flags & SIN_INSERT)
p = oldline; p = oldline;
else else
{
p = skipwhite(p); p = skipwhite(p);
line_len = (int)STRLEN(p) + 1; line_len -= (int)(p - oldline);
}
// If 'preserveindent' and 'expandtab' are both set keep the original // If 'preserveindent' and 'expandtab' are both set keep the original
// characters and allocate accordingly. We will fill the rest with spaces // characters and allocate accordingly. We will fill the rest with spaces
@ -1330,7 +1333,7 @@ change_indent(
// MODE_VREPLACE state needs to know what the line was like before changing // MODE_VREPLACE state needs to know what the line was like before changing
if (State & VREPLACE_FLAG) if (State & VREPLACE_FLAG)
{ {
orig_line = vim_strsave(ml_get_curline()); // Deal with NULL below orig_line = vim_strnsave(ml_get_curline(), ml_get_curline_len()); // Deal with NULL below
orig_col = curwin->w_cursor.col; orig_col = curwin->w_cursor.col;
} }
@ -1508,7 +1511,7 @@ change_indent(
return; return;
// Save new line // Save new line
new_line = vim_strsave(ml_get_curline()); new_line = vim_strnsave(ml_get_curline(), ml_get_curline_len());
if (new_line == NULL) if (new_line == NULL)
return; return;
@ -1758,6 +1761,7 @@ ex_retab(exarg_T *eap)
for (lnum = eap->line1; !got_int && lnum <= eap->line2; ++lnum) for (lnum = eap->line1; !got_int && lnum <= eap->line2; ++lnum)
{ {
ptr = ml_get(lnum); ptr = ml_get(lnum);
old_len = ml_get_len(lnum);
col = 0; col = 0;
vcol = 0; vcol = 0;
did_undo = FALSE; did_undo = FALSE;
@ -1821,7 +1825,6 @@ ex_retab(exarg_T *eap)
// len is actual number of white characters used // len is actual number of white characters used
len = num_spaces + num_tabs; len = num_spaces + num_tabs;
old_len = (long)STRLEN(ptr);
new_len = old_len - col + start_col + len + 1; new_len = old_len - col + start_col + len + 1;
if (new_len <= 0 || new_len >= MAXCOL) if (new_len <= 0 || new_len >= MAXCOL)
{ {
@ -1845,6 +1848,7 @@ ex_retab(exarg_T *eap)
first_line = lnum; first_line = lnum;
last_line = lnum; last_line = lnum;
ptr = new_line; ptr = new_line;
old_len = new_len - 1;
col = start_col + len; col = start_col + len;
} }
} }
@ -2000,8 +2004,7 @@ lisp_match(char_u *p)
while (*word != NUL) while (*word != NUL)
{ {
(void)copy_option_part(&word, buf, LSIZE, ","); len = copy_option_part(&word, buf, LSIZE, ",");
len = (int)STRLEN(buf);
if (STRNCMP(buf, p, len) == 0 && IS_WHITE_OR_NUL(p[len])) if (STRNCMP(buf, p, len) == 0 && IS_WHITE_OR_NUL(p[len]))
return TRUE; return TRUE;
} }

View File

@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1328,
/**/ /**/
1327, 1327,
/**/ /**/