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 <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/clipboard.c b/src/clipboard.c
index 8b9850e..6c8b60c 100644
--- a/src/clipboard.c
+++ b/src/clipboard.c
@@ -2129,7 +2129,7 @@
return -1;
for (i = 0; i < y_ptr->y_size; i++)
- *len += (long_u)STRLEN(y_ptr->y_array[i]) + eolsize;
+ *len += (long_u)y_ptr->y_array[i].length + eolsize;
// Don't want newline character at end of last line if we're in MCHAR mode.
if (y_ptr->y_type == MCHAR && *len >= eolsize)
@@ -2141,9 +2141,9 @@
lnum = 0;
for (i = 0, j = 0; i < (int)*len; i++, j++)
{
- if (y_ptr->y_array[lnum][j] == '\n')
+ if (y_ptr->y_array[lnum].string[j] == '\n')
p[i] = NUL;
- else if (y_ptr->y_array[lnum][j] == NUL)
+ else if (y_ptr->y_array[lnum].string[j] == NUL)
{
# ifdef USE_CRNL
p[i++] = '\r';
@@ -2153,7 +2153,7 @@
j = -1;
}
else
- p[i] = y_ptr->y_array[lnum][j];
+ p[i] = y_ptr->y_array[lnum].string[j];
}
return y_ptr->y_type;
}