Mercurial > vim
comparison src/match.c @ 30574:66de6909e102 v9.0.0622
patch 9.0.0622: matchaddpos() can get slow when adding many matches
Commit: https://github.com/vim/vim/commit/9f573a8df02d9f699a43d2afbd1d2841d700b9ad
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Sep 29 13:50:08 2022 +0100
patch 9.0.0622: matchaddpos() can get slow when adding many matches
Problem: matchaddpos() can get slow when adding many matches.
Solution: Update the next available match ID when manually picking an ID and
remove check if the available ID can be used. (idea by Rick Howe)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 29 Sep 2022 15:00:03 +0200 |
parents | 86683eee58ac |
children | a52697bcffa6 |
comparison
equal
deleted
inserted
replaced
30573:c6b5eb07032a | 30574:66de6909e102 |
---|---|
48 if (id < -1 || id == 0) | 48 if (id < -1 || id == 0) |
49 { | 49 { |
50 semsg(_(e_invalid_id_nr_must_be_greater_than_or_equal_to_one_1), id); | 50 semsg(_(e_invalid_id_nr_must_be_greater_than_or_equal_to_one_1), id); |
51 return -1; | 51 return -1; |
52 } | 52 } |
53 if (id != -1) | 53 if (id == -1) |
54 { | 54 { |
55 cur = wp->w_match_head; | 55 // use the next available match ID |
56 while (cur != NULL) | 56 id = wp->w_next_match_id++; |
57 { | 57 } |
58 else | |
59 { | |
60 // check the given ID is not already in use | |
61 for (cur = wp->w_match_head; cur != NULL; cur = cur->mit_next) | |
58 if (cur->mit_id == id) | 62 if (cur->mit_id == id) |
59 { | 63 { |
60 semsg(_(e_id_already_taken_nr), id); | 64 semsg(_(e_id_already_taken_nr), id); |
61 return -1; | 65 return -1; |
62 } | 66 } |
63 cur = cur->mit_next; | 67 |
64 } | 68 // Make sure the next match ID is always higher than the highest |
65 } | 69 // manually selected ID. Add some extra in case a few more IDs are |
70 // added soon. | |
71 if (wp->w_next_match_id < id + 100) | |
72 wp->w_next_match_id = id + 100; | |
73 } | |
74 | |
66 if ((hlg_id = syn_namen2id(grp, (int)STRLEN(grp))) == 0) | 75 if ((hlg_id = syn_namen2id(grp, (int)STRLEN(grp))) == 0) |
67 { | 76 { |
68 semsg(_(e_no_such_highlight_group_name_str), grp); | 77 semsg(_(e_no_such_highlight_group_name_str), grp); |
69 return -1; | 78 return -1; |
70 } | 79 } |
71 if (pat != NULL && (regprog = vim_regcomp(pat, RE_MAGIC)) == NULL) | 80 if (pat != NULL && (regprog = vim_regcomp(pat, RE_MAGIC)) == NULL) |
72 { | 81 { |
73 semsg(_(e_invalid_argument_str), pat); | 82 semsg(_(e_invalid_argument_str), pat); |
74 return -1; | 83 return -1; |
75 } | |
76 | |
77 // Find available match ID. | |
78 while (id == -1) | |
79 { | |
80 cur = wp->w_match_head; | |
81 while (cur != NULL && cur->mit_id != wp->w_next_match_id) | |
82 cur = cur->mit_next; | |
83 if (cur == NULL) | |
84 id = wp->w_next_match_id; | |
85 wp->w_next_match_id++; | |
86 } | 84 } |
87 | 85 |
88 // Build new match. | 86 // Build new match. |
89 m = ALLOC_CLEAR_ONE(matchitem_T); | 87 m = ALLOC_CLEAR_ONE(matchitem_T); |
90 if (m == NULL) | 88 if (m == NULL) |