vim-patch:9.1.0138: too many STRLEN calls when getting a memline (#27799)

Problem:  too many STRLEN calls when getting a memline
Solution: Optimize calls to STRLEN(), add a few functions in memline.c
          that return the byte length instead of relying on STRLEN()
          (John Marriott)

closes: vim/vim#14052

02d7a6c6cf

Cherry-pick line break changes from patch 8.1.0226.
Cherry-pick ml_line_len from patch 8.1.0579.
Cherry-pick test_comments.vim change from patch 9.1.0153.

Co-authored-by: John Marriott <basilisk@internode.on.net>
This commit is contained in:
zeertzjq
2024-03-10 17:08:00 +08:00
committed by GitHub
parent a441bdc936
commit b465ede2c7
9 changed files with 73 additions and 26 deletions

View File

@@ -514,3 +514,15 @@ char *get_cursor_pos_ptr(void)
{
return ml_get_buf(curbuf, curwin->w_cursor.lnum) + curwin->w_cursor.col;
}
/// @return length (excluding the NUL) of the cursor line.
colnr_T get_cursor_line_len(void)
{
return ml_get_buf_len(curbuf, curwin->w_cursor.lnum);
}
/// @return length (excluding the NUL) of the cursor position.
colnr_T get_cursor_pos_len(void)
{
return ml_get_buf_len(curbuf, curwin->w_cursor.lnum) - curwin->w_cursor.col;
}