comparison src/change.c @ 34532:64edf95a833a v9.1.0168

patch 9.1.0168: too many STRLEN() calls Commit: https://github.com/vim/vim/commit/bfcc895482c717c9f6d86890d789ec739c3016b4 Author: John Marriott <basilisk@internode.on.net> Date: Mon Mar 11 22:04:45 2024 +0100 patch 9.1.0168: too many STRLEN() calls Problem: too many STRLEN() calls Solution: Make use of ml_get_len() calls instead (John Marriott) closes: #14123 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, 11 Mar 2024 22:15:03 +0100
parents 80991201ed38
children b20609f4ab37
comparison
equal deleted inserted replaced
34531:0591aba1489d 34532:64edf95a833a
1054 if (virtual_active() && curwin->w_cursor.coladd > 0) 1054 if (virtual_active() && curwin->w_cursor.coladd > 0)
1055 coladvance_force(getviscol()); 1055 coladvance_force(getviscol());
1056 1056
1057 col = curwin->w_cursor.col; 1057 col = curwin->w_cursor.col;
1058 oldp = ml_get(lnum); 1058 oldp = ml_get(lnum);
1059 linelen = (int)STRLEN(oldp) + 1; 1059 linelen = (int)ml_get_len(lnum) + 1;
1060 1060
1061 // The lengths default to the values for when not replacing. 1061 // The lengths default to the values for when not replacing.
1062 oldlen = 0; 1062 oldlen = 0;
1063 newlen = charlen; 1063 newlen = charlen;
1064 1064
1191 if (virtual_active() && curwin->w_cursor.coladd > 0) 1191 if (virtual_active() && curwin->w_cursor.coladd > 0)
1192 coladvance_force(getviscol()); 1192 coladvance_force(getviscol());
1193 1193
1194 col = curwin->w_cursor.col; 1194 col = curwin->w_cursor.col;
1195 oldp = ml_get(lnum); 1195 oldp = ml_get(lnum);
1196 oldlen = (int)STRLEN(oldp); 1196 oldlen = (int)ml_get_len(lnum);
1197 1197
1198 newp = alloc(oldlen + newlen + 1); 1198 newp = alloc(oldlen + newlen + 1);
1199 if (newp == NULL) 1199 if (newp == NULL)
1200 return; 1200 return;
1201 if (col > 0) 1201 if (col > 0)
1270 int alloc_newp; 1270 int alloc_newp;
1271 long movelen; 1271 long movelen;
1272 int fixpos = fixpos_arg; 1272 int fixpos = fixpos_arg;
1273 1273
1274 oldp = ml_get(lnum); 1274 oldp = ml_get(lnum);
1275 oldlen = (int)STRLEN(oldp); 1275 oldlen = (int)ml_get_len(lnum);
1276 1276
1277 // Can't do anything when the cursor is on the NUL after the line. 1277 // Can't do anything when the cursor is on the NUL after the line.
1278 if (col >= oldlen) 1278 if (col >= oldlen)
1279 return FAIL; 1279 return FAIL;
1280 1280
1434 #ifdef FEAT_PROP_POPUP 1434 #ifdef FEAT_PROP_POPUP
1435 int at_eol; // cursor after last character 1435 int at_eol; // cursor after last character
1436 #endif 1436 #endif
1437 1437
1438 // make a copy of the current line so we can mess with it 1438 // make a copy of the current line so we can mess with it
1439 saved_line = vim_strsave(ml_get_curline()); 1439 saved_line = vim_strnsave(ml_get_curline(), ml_get_curline_len());
1440 if (saved_line == NULL) // out of memory! 1440 if (saved_line == NULL) // out of memory!
1441 return FALSE; 1441 return FALSE;
1442 1442
1443 #ifdef FEAT_PROP_POPUP 1443 #ifdef FEAT_PROP_POPUP
1444 at_eol = curwin->w_cursor.col >= (int)STRLEN(saved_line); 1444 at_eol = curwin->w_cursor.col >= (int)ml_get_curline_len();
1445 #endif 1445 #endif
1446 1446
1447 if (State & VREPLACE_FLAG) 1447 if (State & VREPLACE_FLAG)
1448 { 1448 {
1449 // With MODE_VREPLACE we make a copy of the next line, which we will be 1449 // With MODE_VREPLACE we make a copy of the next line, which we will be
1452 // we grab what it ended up putting on the new line, put back the 1452 // we grab what it ended up putting on the new line, put back the
1453 // original line, and call ins_char() to put each new character onto 1453 // original line, and call ins_char() to put each new character onto
1454 // the line, replacing what was there before and pushing the right 1454 // the line, replacing what was there before and pushing the right
1455 // stuff onto the replace stack. -- webb. 1455 // stuff onto the replace stack. -- webb.
1456 if (curwin->w_cursor.lnum < orig_line_count) 1456 if (curwin->w_cursor.lnum < orig_line_count)
1457 next_line = vim_strsave(ml_get(curwin->w_cursor.lnum + 1)); 1457 next_line = vim_strnsave(ml_get(curwin->w_cursor.lnum + 1), ml_get_len(curwin->w_cursor.lnum + 1));
1458 else 1458 else
1459 next_line = vim_strsave((char_u *)""); 1459 next_line = vim_strsave((char_u *)"");
1460 if (next_line == NULL) // out of memory! 1460 if (next_line == NULL) // out of memory!
1461 goto theend; 1461 goto theend;
1462 1462
2305 // the original line, and inserts the new stuff char by char, pushing old 2305 // the original line, and inserts the new stuff char by char, pushing old
2306 // stuff onto the replace stack (via ins_char()). 2306 // stuff onto the replace stack (via ins_char()).
2307 if (State & VREPLACE_FLAG) 2307 if (State & VREPLACE_FLAG)
2308 { 2308 {
2309 // Put new line in p_extra 2309 // Put new line in p_extra
2310 p_extra = vim_strsave(ml_get_curline()); 2310 p_extra = vim_strnsave(ml_get_curline(), ml_get_curline_len());
2311 if (p_extra == NULL) 2311 if (p_extra == NULL)
2312 goto theend; 2312 goto theend;
2313 2313
2314 // Put back original line 2314 // Put back original line
2315 ml_replace(curwin->w_cursor.lnum, next_line, FALSE); 2315 ml_replace(curwin->w_cursor.lnum, next_line, FALSE);
2350 old_line = ml_get(lnum); 2350 old_line = ml_get(lnum);
2351 if (col == 0) 2351 if (col == 0)
2352 newp = vim_strsave((char_u *)""); 2352 newp = vim_strsave((char_u *)"");
2353 else 2353 else
2354 newp = vim_strnsave(old_line, col); 2354 newp = vim_strnsave(old_line, col);
2355 deleted = (int)STRLEN(old_line) - col; 2355 deleted = (int)ml_get_len(lnum) - col;
2356 2356
2357 if (newp == NULL) 2357 if (newp == NULL)
2358 return FAIL; 2358 return FAIL;
2359 2359
2360 ml_replace(lnum, newp, FALSE); 2360 ml_replace(lnum, newp, FALSE);