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 vim/vim#7279)
232f4612e2
This commit is contained in:
Jan Edmund Lazo 2020-11-11 14:20:28 -05:00
parent 3013d0edfc
commit 6d58f1eace
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15

View File

@ -1970,11 +1970,21 @@ bool has_nvim_version(const char *const version_str)
/// ///
/// @return true if patch `n` has been included. /// @return true if patch `n` has been included.
bool has_vim_patch(int n) bool has_vim_patch(int n)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
for (int i = 0; included_patches[i] != 0; i++) { // Perform a binary search.
if (included_patches[i] == n) { int l = 0;
int h = (int)(ARRAY_SIZE(included_patches)) - 1;
while (l < h) {
const int 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;
} }