Mercurial > vim
comparison src/syntax.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 | 97255d909654 |
children |
comparison
equal
deleted
inserted
replaced
34539:0dbb6f014f5e | 34540:9e093c96dff6 |
---|---|
591 linenr_T end_lnum; | 591 linenr_T end_lnum; |
592 linenr_T break_lnum; | 592 linenr_T break_lnum; |
593 int had_sync_point; | 593 int had_sync_point; |
594 stateitem_T *cur_si; | 594 stateitem_T *cur_si; |
595 synpat_T *spp; | 595 synpat_T *spp; |
596 char_u *line; | |
597 int found_flags = 0; | 596 int found_flags = 0; |
598 int found_match_idx = 0; | 597 int found_match_idx = 0; |
599 linenr_T found_current_lnum = 0; | 598 linenr_T found_current_lnum = 0; |
600 int found_current_col= 0; | 599 int found_current_col= 0; |
601 lpos_T found_m_endpos; | 600 lpos_T found_m_endpos; |
649 /* | 648 /* |
650 * Skip lines that end in a backslash. | 649 * Skip lines that end in a backslash. |
651 */ | 650 */ |
652 for ( ; start_lnum > 1; --start_lnum) | 651 for ( ; start_lnum > 1; --start_lnum) |
653 { | 652 { |
654 line = ml_get(start_lnum - 1); | 653 char_u *l = ml_get(start_lnum - 1); |
655 if (*line == NUL || *(line + STRLEN(line) - 1) != '\\') | 654 |
655 if (*l == NUL || *(l + ml_get_len(start_lnum - 1) - 1) != '\\') | |
656 break; | 656 break; |
657 } | 657 } |
658 current_lnum = start_lnum; | 658 current_lnum = start_lnum; |
659 | 659 |
660 // set cursor to start of search | 660 // set cursor to start of search |
2773 int start_idx; | 2773 int start_idx; |
2774 int best_idx; | 2774 int best_idx; |
2775 regmmatch_T regmatch; | 2775 regmmatch_T regmatch; |
2776 regmmatch_T best_regmatch; // startpos/endpos of best match | 2776 regmmatch_T best_regmatch; // startpos/endpos of best match |
2777 lpos_T pos; | 2777 lpos_T pos; |
2778 char_u *line; | |
2779 int had_match = FALSE; | 2778 int had_match = FALSE; |
2780 char_u buf_chartab[32]; // chartab array for syn option iskyeyword | 2779 char_u buf_chartab[32]; // chartab array for syn option iskyeyword |
2781 | 2780 |
2782 // just in case we are invoked for a keyword | 2781 // just in case we are invoked for a keyword |
2783 if (idx < 0) | 2782 if (idx < 0) |
2897 // If the skip pattern goes on to the next line, there is no | 2896 // If the skip pattern goes on to the next line, there is no |
2898 // match with an end pattern in this line. | 2897 // match with an end pattern in this line. |
2899 if (pos.lnum > startpos->lnum) | 2898 if (pos.lnum > startpos->lnum) |
2900 break; | 2899 break; |
2901 | 2900 |
2902 line = ml_get_buf(syn_buf, startpos->lnum, FALSE); | 2901 line_len = ml_get_buf_len(syn_buf, startpos->lnum); |
2903 line_len = (int)STRLEN(line); | |
2904 | 2902 |
2905 // take care of an empty match or negative offset | 2903 // take care of an empty match or negative offset |
2906 if (pos.col <= matchcol) | 2904 if (pos.col <= matchcol) |
2907 ++matchcol; | 2905 ++matchcol; |
2908 else if (pos.col <= regmatch.endpos[0].col) | 2906 else if (pos.col <= regmatch.endpos[0].col) |
3099 } | 3097 } |
3100 if (result->lnum > syn_buf->b_ml.ml_line_count) | 3098 if (result->lnum > syn_buf->b_ml.ml_line_count) |
3101 { | 3099 { |
3102 // a "\n" at the end of the pattern may take us below the last line | 3100 // a "\n" at the end of the pattern may take us below the last line |
3103 result->lnum = syn_buf->b_ml.ml_line_count; | 3101 result->lnum = syn_buf->b_ml.ml_line_count; |
3104 col = (int)STRLEN(ml_get_buf(syn_buf, result->lnum, FALSE)); | 3102 col = ml_get_buf_len(syn_buf, result->lnum); |
3105 } | 3103 } |
3106 if (off != 0) | 3104 if (off != 0) |
3107 { | 3105 { |
3108 base = ml_get_buf(syn_buf, result->lnum, FALSE); | 3106 base = ml_get_buf(syn_buf, result->lnum, FALSE); |
3109 p = base + col; | 3107 p = base + col; |