diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-03-05 17:03:00 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-03-05 17:04:43 +0800 |
commit | 749fe2c383f662bb13f97336329a0e08200c0a3b (patch) | |
tree | 56afe62b972a441545d3b53fbf3bb7b68ded2188 /src/nvim/quickfix.c | |
parent | 1adad44b7ce6574f505f4cf5df3c8e21c0747f93 (diff) | |
download | rneovim-749fe2c383f662bb13f97336329a0e08200c0a3b.tar.gz rneovim-749fe2c383f662bb13f97336329a0e08200c0a3b.tar.bz2 rneovim-749fe2c383f662bb13f97336329a0e08200c0a3b.zip |
vim-patch:9.0.0770: quickfix commands may keep memory allocated
Problem: Quickfix commands may keep memory allocated.
Solution: Free memory when it's a bit much. (Yegappan Lakshmanan,
closes vim/vim#11379)
https://github.com/vim/vim/commit/d8cd6f7427bc89aa38f42cc44f58bf5fb5f0f972
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/nvim/quickfix.c')
-rw-r--r-- | src/nvim/quickfix.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 51cc7fa30b..3c20c5239c 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -292,12 +292,26 @@ static garray_T *qfga_get(void) ga_init(&qfga, 1, 256); } - // Retain ga_data from previous use. Reset the length to zero. + // Reset the length to zero. Retain ga_data from previous use to avoid + // many alloc/free calls. qfga.ga_len = 0; return &qfga; } +/// The "qfga" grow array buffer is reused across multiple quickfix commands as +/// a temporary buffer to reduce the number of alloc/free calls. But if the +/// buffer size is large, then to avoid holding on to that memory, clear the +/// grow array. Otherwise just reset the grow array length. +static void qfga_clear(void) +{ + if (qfga.ga_maxlen > 1000) { + ga_clear(&qfga); + } else { + qfga.ga_len = 0; + } +} + // Counter to prevent autocmds from freeing up location lists when they are // still being used. static int quickfix_busy = 0; @@ -2847,6 +2861,8 @@ static void qf_jump_print_msg(qf_info_T *qi, int qf_index, qfline_T *qf_ptr, buf msg_ext_set_kind("quickfix"); msg_attr_keep(gap->ga_data, 0, true, false); msg_scroll = (int)i; + + qfga_clear(); } /// Find a usable window for opening a file from the quickfix/location list. If @@ -3204,6 +3220,7 @@ void qf_list(exarg_T *eap) } os_breakcheck(); } + qfga_clear(); } /// Remove newlines and leading whitespace from an error message. @@ -4147,6 +4164,8 @@ static void qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last, int q // Delete the empty line which is now at the end (void)ml_delete(lnum + 1, false); } + + qfga_clear(); } // Correct cursor position. |