mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 06:28:35 +00:00
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:
@@ -3223,8 +3223,7 @@ static void nv_colon(cmdarg_T *cap)
|
||||
clearop(cap->oap);
|
||||
} else if (cap->oap->op_type != OP_NOP
|
||||
&& (cap->oap->start.lnum > curbuf->b_ml.ml_line_count
|
||||
|| cap->oap->start.col >
|
||||
(colnr_T)strlen(ml_get(cap->oap->start.lnum))
|
||||
|| cap->oap->start.col > ml_get_len(cap->oap->start.lnum)
|
||||
|| did_emsg)) {
|
||||
// The start of the operator has become invalid by the Ex command.
|
||||
clearopbeep(cap->oap);
|
||||
@@ -3592,7 +3591,7 @@ bool get_visual_text(cmdarg_T *cap, char **pp, size_t *lenp)
|
||||
}
|
||||
if (VIsual_mode == 'V') {
|
||||
*pp = get_cursor_line_ptr();
|
||||
*lenp = strlen(*pp);
|
||||
*lenp = (size_t)get_cursor_line_len();
|
||||
} else {
|
||||
if (lt(curwin->w_cursor, VIsual)) {
|
||||
*pp = ml_get_pos(&curwin->w_cursor);
|
||||
@@ -4527,9 +4526,8 @@ static void nv_replace(cmdarg_T *cap)
|
||||
}
|
||||
|
||||
// Abort if not enough characters to replace.
|
||||
char *ptr = get_cursor_pos_ptr();
|
||||
if (strlen(ptr) < (unsigned)cap->count1
|
||||
|| (mb_charlen(ptr) < cap->count1)) {
|
||||
if ((size_t)get_cursor_pos_len() < (unsigned)cap->count1
|
||||
|| (mb_charlen(get_cursor_pos_ptr()) < cap->count1)) {
|
||||
clearopbeep(cap->oap);
|
||||
return;
|
||||
}
|
||||
@@ -5347,7 +5345,7 @@ static void nv_gi_cmd(cmdarg_T *cap)
|
||||
if (curbuf->b_last_insert.mark.lnum != 0) {
|
||||
curwin->w_cursor = curbuf->b_last_insert.mark;
|
||||
check_cursor_lnum(curwin);
|
||||
int i = (int)strlen(get_cursor_line_ptr());
|
||||
int i = (int)get_cursor_line_len();
|
||||
if (curwin->w_cursor.col > (colnr_T)i) {
|
||||
if (virtual_active()) {
|
||||
curwin->w_cursor.coladd += curwin->w_cursor.col - i;
|
||||
@@ -6036,7 +6034,7 @@ bool unadjust_for_sel(void)
|
||||
mark_mb_adjustpos(curbuf, pp);
|
||||
} else if (pp->lnum > 1) {
|
||||
pp->lnum--;
|
||||
pp->col = (colnr_T)strlen(ml_get(pp->lnum));
|
||||
pp->col = ml_get_len(pp->lnum);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user