patch 9.1.1137: ins_str() is inefficient by calling STRLEN()

Problem:  ins_str() is inefficient by calling STRLLEN()
Solution: refactor ins_str() to take a length argument
          and let all callers provide the correct length
          when calling ins_str() (John Marriott)

closes: #16711

Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/insexpand.c b/src/insexpand.c
index dc8c76b..deae1ce 100644
--- a/src/insexpand.c
+++ b/src/insexpand.c
@@ -4402,7 +4402,7 @@
     // In insert mode: Delete the typed part.
     // In replace mode: Put the old characters back, if any.
     int col = compl_col + (compl_status_adding() ? compl_length : 0);
-    char_u  *remaining = NULL;
+    string_T	remaining = {NULL, 0};
     int	    orig_col;
     int	has_preinsert = ins_compl_preinsert_effect();
     if (has_preinsert)
@@ -4415,18 +4415,18 @@
     {
 	if (curwin->w_cursor.col < ml_get_curline_len())
 	{
-	    char_u *line = ml_get_curline();
-	    remaining = vim_strnsave(line + curwin->w_cursor.col,
-				(size_t)STRLEN(line + curwin->w_cursor.col));
-	    if (remaining == NULL)
+	    char_u *line = ml_get_cursor();
+	    remaining.length = ml_get_cursor_len();
+	    remaining.string = vim_strnsave(line, remaining.length);
+	    if (remaining.string == NULL)
 		return;
 	}
 	while (curwin->w_cursor.lnum > compl_lnum)
 	{
 	    if (ml_delete(curwin->w_cursor.lnum) == FAIL)
 	    {
-		if (remaining)
-		    VIM_CLEAR(remaining);
+		if (remaining.string)
+		    vim_free(remaining.string);
 		return;
 	    }
 	    deleted_lines_mark(curwin->w_cursor.lnum, 1L);
@@ -4440,20 +4440,20 @@
     {
 	if (stop_arrow() == FAIL)
 	{
-	    if (remaining)
-		VIM_CLEAR(remaining);
+	    if (remaining.string)
+		vim_free(remaining.string);
 	    return;
 	}
 	backspace_until_column(col);
 	compl_ins_end_col = curwin->w_cursor.col;
     }
 
-    if (remaining != NULL)
+    if (remaining.string != NULL)
     {
 	orig_col = curwin->w_cursor.col;
-	ins_str(remaining);
+	ins_str(remaining.string, remaining.length);
 	curwin->w_cursor.col = orig_col;
-	vim_free(remaining);
+	vim_free(remaining.string);
     }
     // TODO: is this sufficient for redrawing?  Redrawing everything causes
     // flicker, thus we can't do that.