Mercurial > vim
diff src/normal.c @ 34434:89f9a7925fff v9.1.0138
patch 9.1.0138: too many STRLEN calls when getting a memline
Commit: https://github.com/vim/vim/commit/02d7a6c6cfceb3faf9c98fcb7c458760cd50d269
Author: John Marriott <basilisk@internode.on.net>
Date: Mon Feb 26 21:21:17 2024 +0100
patch 9.1.0138: too many STRLEN calls when getting a memline
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: #14052
Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 26 Feb 2024 21:30:03 +0100 |
parents | 6be721794e1f |
children | e21d2759a5c2 |
line wrap: on
line diff
--- a/src/normal.c +++ b/src/normal.c @@ -3225,8 +3225,7 @@ 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. @@ -3675,7 +3674,7 @@ get_visual_text( if (VIsual_mode == 'V') { *pp = ml_get_curline(); - *lenp = (int)STRLEN(*pp); + *lenp = (int)ml_get_curline_len(); } else { @@ -4768,7 +4767,6 @@ nv_kundo(cmdarg_T *cap) static void nv_replace(cmdarg_T *cap) { - char_u *ptr; int had_ctrl_v; long n; @@ -4835,9 +4833,8 @@ nv_replace(cmdarg_T *cap) } // Abort if not enough characters to replace. - ptr = ml_get_cursor(); - if (STRLEN(ptr) < (unsigned)cap->count1 - || (has_mbyte && mb_charlen(ptr) < cap->count1)) + if ((size_t)ml_get_cursor_len() < (unsigned)cap->count1 + || (has_mbyte && mb_charlen(ml_get_cursor()) < cap->count1)) { clearopbeep(cap->oap); return; @@ -4917,11 +4914,13 @@ nv_replace(cmdarg_T *cap) } else { + char_u *ptr; + // Replace the characters within one line. for (n = cap->count1; n > 0; --n) { - // Get ptr again, because u_save and/or showmatch() will have - // released the line. This may also happen in ins_copychar(). + // Get ptr again, because ins_copychar() and showmatch() + // will have released the line. // At the same time we let know that the line will be changed. if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) { @@ -4945,6 +4944,7 @@ nv_replace(cmdarg_T *cap) if (netbeans_active()) { colnr_T start = (colnr_T)(curwin->w_cursor.col - cap->count1); + ptr = ml_get_curline(); netbeans_removed(curbuf, curwin->w_cursor.lnum, start, cap->count1); @@ -5130,7 +5130,7 @@ n_swapchar(cmdarg_T *cap) if (did_change) { ptr = ml_get(pos.lnum); - count = (int)STRLEN(ptr) - pos.col; + count = (int)ml_get_len(pos.lnum) - pos.col; netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); // line may have been flushed, get it again @@ -5919,7 +5919,7 @@ nv_gi_cmd(cmdarg_T *cap) { curwin->w_cursor = curbuf->b_last_insert; check_cursor_lnum(); - i = (int)STRLEN(ml_get_curline()); + i = (int)ml_get_curline_len(); if (curwin->w_cursor.col > (colnr_T)i) { if (virtual_active()) @@ -6717,7 +6717,7 @@ unadjust_for_sel(void) 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; } }