mirror of
https://github.com/neovim/neovim.git
synced 2025-10-18 07:41:51 +00:00
vim-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 vim/vim#4012) Make assert_inrange() accept float values.
38f08e76ac
Omit changes to typval_compare()
because patch v8.0.1505 was not ported.
This commit is contained in:
@@ -5867,6 +5867,32 @@ int assert_inrange(typval_T *argvars)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
bool error = false;
|
||||
|
||||
if (argvars[0].v_type == VAR_FLOAT
|
||||
|| argvars[1].v_type == VAR_FLOAT
|
||||
|| argvars[2].v_type == VAR_FLOAT) {
|
||||
const float_T flower = tv_get_float(&argvars[0]);
|
||||
const float_T fupper = tv_get_float(&argvars[1]);
|
||||
const float_T factual = tv_get_float(&argvars[2]);
|
||||
|
||||
if (factual < flower || factual > fupper) {
|
||||
garray_T ga;
|
||||
prepare_assert_error(&ga);
|
||||
if (argvars[3].v_type != VAR_UNKNOWN) {
|
||||
char_u *const tofree = (char_u *)encode_tv2string(&argvars[3], NULL);
|
||||
ga_concat(&ga, tofree);
|
||||
xfree(tofree);
|
||||
} else {
|
||||
char msg[80];
|
||||
vim_snprintf(msg, sizeof(msg), "Expected range %g - %g, but got %g",
|
||||
flower, fupper, factual);
|
||||
ga_concat(&ga, (char_u *)msg);
|
||||
}
|
||||
assert_error(&ga);
|
||||
ga_clear(&ga);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
const varnumber_T lower = tv_get_number_chk(&argvars[0], &error);
|
||||
const varnumber_T upper = tv_get_number_chk(&argvars[1], &error);
|
||||
const varnumber_T actual = tv_get_number_chk(&argvars[2], &error);
|
||||
@@ -5888,6 +5914,7 @@ int assert_inrange(typval_T *argvars)
|
||||
ga_clear(&ga);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -559,7 +559,9 @@ static char_u *nfa_get_match_text(nfa_state_T *start)
|
||||
*/
|
||||
static void realloc_post_list(void)
|
||||
{
|
||||
size_t new_max = (post_end - post_start) + 1000;
|
||||
// For weird patterns the number of states can be very high. Increasing by
|
||||
// 50% seems a reasonable compromise between memory use and speed.
|
||||
const size_t new_max = (post_end - post_start) * 3 / 2;
|
||||
int *new_start = xrealloc(post_start, new_max * sizeof(int));
|
||||
post_ptr = new_start + (post_ptr - post_start);
|
||||
post_end = new_start + new_max;
|
||||
|
@@ -52,6 +52,37 @@ func Test_assert_fails_in_try_block()
|
||||
endtry
|
||||
endfunc
|
||||
|
||||
func Test_assert_inrange()
|
||||
call assert_equal(0, assert_inrange(7, 7, 7))
|
||||
call assert_equal(0, assert_inrange(5, 7, 5))
|
||||
call assert_equal(0, assert_inrange(5, 7, 6))
|
||||
call assert_equal(0, assert_inrange(5, 7, 7))
|
||||
call assert_equal(1, assert_inrange(5, 7, 4))
|
||||
call assert_match("Expected range 5 - 7, but got 4", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
call assert_equal(1, assert_inrange(5, 7, 8))
|
||||
call assert_match("Expected range 5 - 7, but got 8", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
|
||||
call assert_fails('call assert_inrange(1, 1)', 'E119:')
|
||||
|
||||
if has('float')
|
||||
call assert_equal(0, assert_inrange(7.0, 7, 7))
|
||||
call assert_equal(0, assert_inrange(7, 7.0, 7))
|
||||
call assert_equal(0, assert_inrange(7, 7, 7.0))
|
||||
call assert_equal(0, assert_inrange(5, 7, 5.0))
|
||||
call assert_equal(0, assert_inrange(5, 7, 6.0))
|
||||
call assert_equal(0, assert_inrange(5, 7, 7.0))
|
||||
|
||||
call assert_equal(1, assert_inrange(5, 7, 4.0))
|
||||
call assert_match("Expected range 5.0 - 7.0, but got 4.0", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
call assert_equal(1, assert_inrange(5, 7, 8.0))
|
||||
call assert_match("Expected range 5.0 - 7.0, but got 8.0", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
endif
|
||||
endfunc
|
||||
|
||||
" Must be last.
|
||||
func Test_zz_quit_detected()
|
||||
" Verify that if a test function ends Vim the test script detects this.
|
||||
|
@@ -39,6 +39,17 @@ func Test_range_with_newline()
|
||||
bwipe!
|
||||
endfunc
|
||||
|
||||
func Test_pattern_compile_speed()
|
||||
if !exists('+spellcapcheck') || !has('reltime')
|
||||
return
|
||||
endif
|
||||
let start = reltime()
|
||||
" this used to be very slow, not it should be about a second
|
||||
set spc=\\v(((((Nxxxxxxx&&xxxx){179})+)+)+){179}
|
||||
call assert_inrange(0.01, 10.0, reltimefloat(reltime(start)))
|
||||
set spc=
|
||||
endfunc
|
||||
|
||||
func Test_get_equi_class()
|
||||
new
|
||||
" Incomplete equivalence class caused invalid memory access
|
||||
|
Reference in New Issue
Block a user