summaryrefslogtreecommitdiffstats
path: root/src/normal.c
diff options
context:
space:
mode:
authorJohn Marriott <basilisk@internode.on.net>2024-02-26 21:21:17 +0100
committerChristian Brabandt <cb@256bit.org>2024-02-26 21:25:03 +0100
commit02d7a6c6cfceb3faf9c98fcb7c458760cd50d269 (patch)
treee80dca75f8301ec9fbdf59936ce8842f5973c57f /src/normal.c
parent2c51e15b66a4be9b5134c495ef546479aaa89ce9 (diff)
patch 9.1.0138: too many STRLEN calls when getting a memlinev9.1.0138
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>
Diffstat (limited to 'src/normal.c')
-rw-r--r--src/normal.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/normal.c b/src/normal.c
index 8a10b86d75..015a250781 100644
--- 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;
}
}