Mercurial > vim
comparison src/ex_cmds.c @ 34540:9e093c96dff6 v9.1.0172
patch 9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Commit: https://github.com/vim/vim/commit/94b7c3233ef534acc669b3083ed1fe59cf3a090b
Author: zeertzjq <zeertzjq@outlook.com>
Date: Tue Mar 12 21:50:32 2024 +0100
patch 9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Problem: More code can use ml_get_buf_len() instead of STRLEN().
Solution: Change more STRLEN() calls to ml_get_buf_len(). Also do not
set ml_line_textlen in ml_replace_len() if "has_props" is set,
because "len_arg" also includes the size of text properties in
that case. (zeertzjq)
closes: #14183
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 12 Mar 2024 22:00:04 +0100 |
parents | dd8f5311cee5 |
children | 3b8ed014a445 |
comparison
equal
deleted
inserted
replaced
34539:0dbb6f014f5e | 34540:9e093c96dff6 |
---|---|
487 * Also get the longest line length for allocating "sortbuf". | 487 * Also get the longest line length for allocating "sortbuf". |
488 */ | 488 */ |
489 for (lnum = eap->line1; lnum <= eap->line2; ++lnum) | 489 for (lnum = eap->line1; lnum <= eap->line2; ++lnum) |
490 { | 490 { |
491 s = ml_get(lnum); | 491 s = ml_get(lnum); |
492 len = (int)STRLEN(s); | 492 len = ml_get_len(lnum); |
493 if (maxlen < len) | 493 if (maxlen < len) |
494 maxlen = len; | 494 maxlen = len; |
495 | 495 |
496 start_col = 0; | 496 start_col = 0; |
497 end_col = len; | 497 end_col = len; |
689 */ | 689 */ |
690 if (u_save(dest, dest + 1) == FAIL) | 690 if (u_save(dest, dest + 1) == FAIL) |
691 return FAIL; | 691 return FAIL; |
692 for (extra = 0, l = line1; l <= line2; l++) | 692 for (extra = 0, l = line1; l <= line2; l++) |
693 { | 693 { |
694 str = vim_strsave(ml_get(l + extra)); | 694 str = vim_strnsave(ml_get(l + extra), ml_get_len(l + extra)); |
695 if (str != NULL) | 695 if (str != NULL) |
696 { | 696 { |
697 ml_append(dest + l - line1, str, (colnr_T)0, FALSE); | 697 ml_append(dest + l - line1, str, (colnr_T)0, FALSE); |
698 vim_free(str); | 698 vim_free(str); |
699 if (dest < line1) | 699 if (dest < line1) |
822 return; | 822 return; |
823 | 823 |
824 curwin->w_cursor.lnum = n; | 824 curwin->w_cursor.lnum = n; |
825 while (line1 <= line2) | 825 while (line1 <= line2) |
826 { | 826 { |
827 // need to use vim_strsave() because the line will be unlocked within | 827 // need to make a copy because the line will be unlocked within |
828 // ml_append() | 828 // ml_append() |
829 p = vim_strsave(ml_get(line1)); | 829 p = vim_strnsave(ml_get(line1), ml_get_len(line1)); |
830 if (p != NULL) | 830 if (p != NULL) |
831 { | 831 { |
832 ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE); | 832 ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE); |
833 vim_free(p); | 833 vim_free(p); |
834 } | 834 } |
4223 if (lnum > curbuf->b_ml.ml_line_count) | 4223 if (lnum > curbuf->b_ml.ml_line_count) |
4224 break; | 4224 break; |
4225 | 4225 |
4226 if (sub_firstline == NULL) | 4226 if (sub_firstline == NULL) |
4227 { | 4227 { |
4228 sub_firstline = vim_strsave(ml_get(sub_firstlnum)); | 4228 sub_firstline = vim_strnsave(ml_get(sub_firstlnum), |
4229 ml_get_len(sub_firstlnum)); | |
4229 if (sub_firstline == NULL) | 4230 if (sub_firstline == NULL) |
4230 { | 4231 { |
4231 vim_free(new_start); | 4232 vim_free(new_start); |
4232 goto outofmem; | 4233 goto outofmem; |
4233 } | 4234 } |
4377 // There already was a substitution, we would | 4378 // There already was a substitution, we would |
4378 // like to show this to the user. We cannot | 4379 // like to show this to the user. We cannot |
4379 // really update the line, it would change | 4380 // really update the line, it would change |
4380 // what matches. Temporarily replace the line | 4381 // what matches. Temporarily replace the line |
4381 // and change it back afterwards. | 4382 // and change it back afterwards. |
4382 orig_line = vim_strsave(ml_get(lnum)); | 4383 orig_line = vim_strnsave(ml_get(lnum), |
4384 ml_get_len(lnum)); | |
4383 if (orig_line != NULL) | 4385 if (orig_line != NULL) |
4384 { | 4386 { |
4385 char_u *new_line = concat_str(new_start, | 4387 char_u *new_line = concat_str(new_start, |
4386 sub_firstline + copycol); | 4388 sub_firstline + copycol); |
4387 | 4389 |
4723 // line and continue in that one. | 4725 // line and continue in that one. |
4724 if (nmatch > 1) | 4726 if (nmatch > 1) |
4725 { | 4727 { |
4726 sub_firstlnum += nmatch - 1; | 4728 sub_firstlnum += nmatch - 1; |
4727 vim_free(sub_firstline); | 4729 vim_free(sub_firstline); |
4728 sub_firstline = vim_strsave(ml_get(sub_firstlnum)); | 4730 sub_firstline = vim_strnsave(ml_get(sub_firstlnum), |
4731 ml_get_len(sub_firstlnum)); | |
4729 // When going beyond the last line, stop substituting. | 4732 // When going beyond the last line, stop substituting. |
4730 if (sub_firstlnum <= line2) | 4733 if (sub_firstlnum <= line2) |
4731 do_again = TRUE; | 4734 do_again = TRUE; |
4732 else | 4735 else |
4733 subflags.do_all = FALSE; | 4736 subflags.do_all = FALSE; |