Skip to content

Commit

Permalink
updated for version 7.3.1018
Browse files Browse the repository at this point in the history
Problem:    New regexp engine wastes memory.
Solution:   Allocate prog with actual number of states, not estimated maximum
            number of sates.
  • Loading branch information
brammool committed May 25, 2013
1 parent 4b41706 commit aae4883
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/regexp_nfa.c
Expand Up @@ -3758,7 +3758,7 @@ nfa_regcomp(expr, re_flags)
char_u *expr;
int re_flags;
{
nfa_regprog_T *prog;
nfa_regprog_T *prog = NULL;
size_t prog_size;
int *postfix;

Expand All @@ -3774,15 +3774,8 @@ nfa_regcomp(expr, re_flags)
if (nfa_regcomp_start(expr, re_flags) == FAIL)
return NULL;

/* Space for compiled regexp */
prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * nstate_max;
prog = (nfa_regprog_T *)lalloc(prog_size, TRUE);
if (prog == NULL)
goto fail;
vim_memset(prog, 0, prog_size);

/* Build postfix form of the regexp. Needed to build the NFA
* (and count its size) */
* (and count its size). */
postfix = re2post();
if (postfix == NULL)
goto fail; /* Cascaded (syntax?) error */
Expand All @@ -3809,6 +3802,13 @@ nfa_regcomp(expr, re_flags)
* Count number of NFA states in "nstate". Do not build the NFA.
*/
post2nfa(postfix, post_ptr, TRUE);

/* Space for compiled regexp */
prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * nstate;
prog = (nfa_regprog_T *)lalloc(prog_size, TRUE);
if (prog == NULL)
goto fail;
vim_memset(prog, 0, prog_size);
state_ptr = prog->state;

/*
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -728,6 +728,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1018,
/**/
1017,
/**/
Expand Down

0 comments on commit aae4883

Please sign in to comment.