Skip to content

Commit 79f6ffd

Browse files
John Marriottchrisbra
authored andcommitted
patch 9.1.0824: too many strlen() calls in register.c
Problem: too many strlen() calls in register.c Solution: refactor code, add string_T struct to keep track of string lengths (John Marriott) closes: #15952 Signed-off-by: John Marriott <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent a68bd6f commit 79f6ffd

6 files changed

Lines changed: 228 additions & 140 deletions

File tree

src/clipboard.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@ clip_convert_selection(char_u **str, long_u *len, Clipboard_T *cbd)
21292129
return -1;
21302130

21312131
for (i = 0; i < y_ptr->y_size; i++)
2132-
*len += (long_u)STRLEN(y_ptr->y_array[i]) + eolsize;
2132+
*len += (long_u)y_ptr->y_array[i].length + eolsize;
21332133

21342134
// Don't want newline character at end of last line if we're in MCHAR mode.
21352135
if (y_ptr->y_type == MCHAR && *len >= eolsize)
@@ -2141,9 +2141,9 @@ clip_convert_selection(char_u **str, long_u *len, Clipboard_T *cbd)
21412141
lnum = 0;
21422142
for (i = 0, j = 0; i < (int)*len; i++, j++)
21432143
{
2144-
if (y_ptr->y_array[lnum][j] == '\n')
2144+
if (y_ptr->y_array[lnum].string[j] == '\n')
21452145
p[i] = NUL;
2146-
else if (y_ptr->y_array[lnum][j] == NUL)
2146+
else if (y_ptr->y_array[lnum].string[j] == NUL)
21472147
{
21482148
# ifdef USE_CRNL
21492149
p[i++] = '\r';
@@ -2153,7 +2153,7 @@ clip_convert_selection(char_u **str, long_u *len, Clipboard_T *cbd)
21532153
j = -1;
21542154
}
21552155
else
2156-
p[i] = y_ptr->y_array[lnum][j];
2156+
p[i] = y_ptr->y_array[lnum].string[j];
21572157
}
21582158
return y_ptr->y_type;
21592159
}

src/macros.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,15 @@
367367
} \
368368
} while (0)
369369

370+
/*
371+
* Free a string and set it's pointer to NULL and length to 0
372+
*/
373+
#define VIM_CLEAR_STRING(s) \
374+
do { \
375+
VIM_CLEAR(s.string); \
376+
s.length = 0; \
377+
} while (0)
378+
370379
// Whether a command index indicates a user command.
371380
#define IS_USER_CMDIDX(idx) ((int)(idx) < 0)
372381

0 commit comments

Comments
 (0)