diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-11-11 14:20:28 -0500 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-11-11 14:36:00 -0500 |
commit | 6d58f1eacef4be410c424f5f0e23c20ffdd791be (patch) | |
tree | 49c4bdad9cf406a826c9b4450bfdef91f8a545af /src | |
parent | 3013d0edfce3a53ef902decfa1f70c596c828471 (diff) | |
download | rneovim-6d58f1eacef4be410c424f5f0e23c20ffdd791be.tar.gz rneovim-6d58f1eacef4be410c424f5f0e23c20ffdd791be.tar.bz2 rneovim-6d58f1eacef4be410c424f5f0e23c20ffdd791be.zip |
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)
https://github.com/vim/vim/commit/232f4612e2b0a6a205ae385740078f6b8af05e75
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/version.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/nvim/version.c b/src/nvim/version.c index 32cb0091a3..7296c74109 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -1970,11 +1970,21 @@ bool has_nvim_version(const char *const version_str) /// /// @return true if patch `n` has been included. bool has_vim_patch(int n) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - for (int i = 0; included_patches[i] != 0; i++) { - if (included_patches[i] == n) { + // Perform a binary search. + 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; } + if (included_patches[m] < n) { + h = m; + } else { + l = m + 1; + } } return false; } |