Skip to content

Commit 232f461

Browse files
committed
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)
1 parent 5e1f22f commit 232f461

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

src/version.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
1973,
753755
/**/
754756
1972,
755757
/**/
@@ -4725,11 +4727,21 @@ highest_patch(void)
47254727
int
47264728
has_patch(int n)
47274729
{
4728-
int i;
4730+
int h, m, l;
47294731

4730-
for (i = 0; included_patches[i] != 0; ++i)
4731-
if (included_patches[i] == n)
4732+
// Perform a binary search.
4733+
l = 0;
4734+
h = (int)(sizeof(included_patches) / sizeof(included_patches[0])) - 1;
4735+
while (l < h)
4736+
{
4737+
m = (l + h) / 2;
4738+
if (included_patches[m] == n)
47324739
return TRUE;
4740+
if (included_patches[m] < n)
4741+
h = m;
4742+
else
4743+
l = m + 1;
4744+
}
47334745
return FALSE;
47344746
}
47354747
#endif
@@ -4941,9 +4953,7 @@ list_version(void)
49414953
{
49424954
msg_puts(_("\nIncluded patches: "));
49434955
first = -1;
4944-
// find last one
4945-
for (i = 0; included_patches[i] != 0; ++i)
4946-
;
4956+
i = (int)(sizeof(included_patches) / sizeof(included_patches[0])) - 1;
49474957
while (--i >= 0)
49484958
{
49494959
if (first < 0)

0 commit comments

Comments
 (0)