Mercurial > vim
diff src/regexp_nfa.c @ 15904:fec4416adb80 v8.1.0958
patch 8.1.0958: compiling weird regexp pattern is very slow
commit https://github.com/vim/vim/commit/38f08e76acf7d21bb34cf8f79f0f82eb63cdc987
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Feb 20 22:04:32 2019 +0100
patch 8.1.0958: compiling weird regexp pattern is very slow
Problem: Compiling weird regexp pattern is very slow.
Solution: When reallocating post list increase size by 50%. (Kuang-che Wu,
closes #4012) Make assert_inrange() accept float values.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 20 Feb 2019 22:15:05 +0100 |
parents | 0c49755f460e |
children | 98d315176d48 |
line wrap: on
line diff
--- a/src/regexp_nfa.c +++ b/src/regexp_nfa.c @@ -509,10 +509,13 @@ nfa_get_match_text(nfa_state_T *start) realloc_post_list(void) { int nstate_max = (int)(post_end - post_start); - int new_max = nstate_max + 1000; + int new_max; int *new_start; int *old_start; + // For weird patterns the number of states can be very high. Increasing by + // 50% seems a reasonable compromise between memory use and speed. + new_max = nstate_max * 3 / 2; new_start = (int *)lalloc(new_max * sizeof(int), TRUE); if (new_start == NULL) return FAIL;