summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-11-10 20:54:29 +0100
committerBram Moolenaar <Bram@vim.org>2020-11-10 20:54:29 +0100
commit232f4612e2b0a6a205ae385740078f6b8af05e75 (patch)
treea0333728fab8b5cbb0101d2b417ba0b919c2e76e
parent5e1f22ff614821b8fc7294c9dd22765acd403aeb (diff)
downloadvim-git-232f4612e2b0a6a205ae385740078f6b8af05e75.tar.gz
patch 8.2.1973: finding a patch number can be a bit slowv8.2.1973
Problem: Finding a patch number can be a bit slow. Solution: Use binary search. (closes #7279)
-rw-r--r--src/version.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/version.c b/src/version.c
index e2affa79e..8535ac554 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1973,
+/**/
1972,
/**/
1971,
@@ -4725,11 +4727,21 @@ highest_patch(void)
int
has_patch(int n)
{
- int i;
+ int h, m, l;
- for (i = 0; included_patches[i] != 0; ++i)
- if (included_patches[i] == n)
+ // Perform a binary search.
+ 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;
+ if (included_patches[m] < n)
+ h = m;
+ else
+ l = m + 1;
+ }
return FALSE;
}
#endif
@@ -4941,9 +4953,7 @@ list_version(void)
{
msg_puts(_("\nIncluded patches: "));
first = -1;
- // find last one
- for (i = 0; included_patches[i] != 0; ++i)
- ;
+ i = (int)(sizeof(included_patches) / sizeof(included_patches[0])) - 1;
while (--i >= 0)
{
if (first < 0)