Please let me tell you another proposal.
The original problem is that w_next_match_id has to be *always* checked
the duplicate with formerly assigned manual ids.
I introduced 2 new variables
w_manual_match_id_min
w_manual_match_id_max
to remember the historical minimum and maximum match ids of manuals.
If w_next_match_id is between those 2 variables, need to check the
duplicate same as currently.
Otherwise, it can simply use w_next_match_id witout the check.
As a result,
matchaddpos('ToDo', [[1]], 10) returns 4
matchaddpos('ToDo', [[1]], 10, 1000) returns 1000
matchaddpos('ToDo', [[1]], 10) returns 5
matchaddpos('ToDo', [[1]], 10) returns 6
matchaddpos('ToDo', [[1]], 10, 500) returns 500
matchaddpos('ToDo', [[1]], 10) returns 7
matchaddpos('ToDo', [[1]], 10, 2000) returns 2000
matchaddpos('ToDo', [[1]], 10) returns 8
as same as currently but make them 2 times faster.
Is there any concerns? How acceptable is it?
Note that, in this proposal,
w_next_match_id
w_manual_match_id_min
w_manual_match_id_max
are initialized in clear_matches() and
when the last id is deleted in match_delete().
However, I am not sure why, w_next_match_id is not initialzed
in the latest verison.
Is it really necessary to remain those 3 variables even when all cleared?
--- structsOrig.h 2018-07-01 10:31:57.808844900 +0900
+++ structs.h 2018-07-19 12:55:14.193517500 +0900
@@ -2887,6 +2887,8 @@
#ifdef FEAT_SEARCH_EXTRA
matchitem_T *w_match_head; /* head of match list */
int w_next_match_id; /* next match ID */
+ int w_manual_match_id_min; /* minimum match ID of manuals
*/
+ int w_manual_match_id_max; /* maximum match ID of manuals
*/
#endif
/*
--- windowOrig.c 2018-06-18 11:30:50.923586100 +0900
+++ window.c 2018-07-19 12:53:29.891734300 +0900
@@ -4620,6 +4620,8 @@
#ifdef FEAT_SEARCH_EXTRA
new_wp->w_match_head = NULL;
new_wp->w_next_match_id = 4;
+ new_wp->w_manual_match_id_min = INT_MAX;
+ new_wp->w_manual_match_id_max = INT_MIN;
#endif
return new_wp;
}
@@ -6803,6 +6805,32 @@
}
cur = cur->next;
}
+ if (id < wp->w_manual_match_id_min)
+ wp->w_manual_match_id_min = id;
+ if (id > wp->w_manual_match_id_max)
+ wp->w_manual_match_id_max = id;
+ }
+ else
+ {
+ if (wp->w_manual_match_id_min <= wp->w_next_match_id &&
+ wp->w_next_match_id <= wp->w_manual_match_id_max)
+ {
+ /* Find available match ID. */
+ while (id == -1)
+ {
+ cur = wp->w_match_head;
+ while (cur != NULL && cur->id != wp->w_next_match_id)
+ cur = cur->next;
+ if (cur == NULL)
+ id = wp->w_next_match_id;
+ wp->w_next_match_id++;
+ }
+ }
+ else
+ {
+ id = wp->w_next_match_id;
+ wp->w_next_match_id++;
+ }
}
if ((hlg_id = syn_namen2id(grp, (int)STRLEN(grp))) == 0)
{
@@ -6815,17 +6843,6 @@
return -1;
}
- /* Find available match ID. */
- while (id == -1)
- {
- cur = wp->w_match_head;
- while (cur != NULL && cur->id != wp->w_next_match_id)
- cur = cur->next;
- if (cur == NULL)
- id = wp->w_next_match_id;
- wp->w_next_match_id++;
- }
-
/* Build new match. */
m = (matchitem_T *)alloc_clear(sizeof(matchitem_T));
m->id = id;
@@ -6994,6 +7011,12 @@
wp->w_match_head = cur->next;
else
prev->next = cur->next;
+ if (wp->w_match_head == NULL)
+ {
+ wp->w_next_match_id = 4;
+ wp->w_manual_match_id_min = INT_MAX;
+ wp->w_manual_match_id_max = INT_MIN;
+ }
vim_regfree(cur->match.regprog);
vim_free(cur->pattern);
if (cur->pos.toplnum != 0)
@@ -7035,6 +7058,9 @@
vim_free(wp->w_match_head);
wp->w_match_head = m;
}
+ wp->w_next_match_id = 4;
+ wp->w_manual_match_id_min = INT_MAX;
+ wp->w_manual_match_id_max = INT_MIN;
redraw_later(SOME_VALID);
}
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.