forked from aniani/vim
patch 8.2.1973: finding a patch number can be a bit slow
Problem: Finding a patch number can be a bit slow. Solution: Use binary search. (closes #7279)
This commit is contained in:
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1973,
|
||||||
/**/
|
/**/
|
||||||
1972,
|
1972,
|
||||||
/**/
|
/**/
|
||||||
@@ -4725,11 +4727,21 @@ highest_patch(void)
|
|||||||
int
|
int
|
||||||
has_patch(int n)
|
has_patch(int n)
|
||||||
{
|
{
|
||||||
int i;
|
int h, m, l;
|
||||||
|
|
||||||
for (i = 0; included_patches[i] != 0; ++i)
|
// Perform a binary search.
|
||||||
if (included_patches[i] == n)
|
l = 0;
|
||||||
|
h = (int)(sizeof(included_patches) / sizeof(included_patches[0])) - 1;
|
||||||
|
while (l < h)
|
||||||
|
{
|
||||||
|
m = (l + h) / 2;
|
||||||
|
if (included_patches[m] == n)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
if (included_patches[m] < n)
|
||||||
|
h = m;
|
||||||
|
else
|
||||||
|
l = m + 1;
|
||||||
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -4941,9 +4953,7 @@ list_version(void)
|
|||||||
{
|
{
|
||||||
msg_puts(_("\nIncluded patches: "));
|
msg_puts(_("\nIncluded patches: "));
|
||||||
first = -1;
|
first = -1;
|
||||||
// find last one
|
i = (int)(sizeof(included_patches) / sizeof(included_patches[0])) - 1;
|
||||||
for (i = 0; included_patches[i] != 0; ++i)
|
|
||||||
;
|
|
||||||
while (--i >= 0)
|
while (--i >= 0)
|
||||||
{
|
{
|
||||||
if (first < 0)
|
if (first < 0)
|
||||||
|
Reference in New Issue
Block a user