Subject: Re: [BUG] Long line makes pattern matching (by //) hog Zsh
From: Bart Schaefer <[email-masked]>
To: Zsh hackers list <[email-masked]>
Date: Sun, 5 Jun 2016 12:10:20 -0700
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Jun 5,  4:36pm, Sebastian Gniazdowski wrote:
}
} 1. not backslash nor slash nor space [^ /\\\\]##
} 2. not number, slash, backslash, space [^0-9/\\\\ ]##
} 3. not slash, backslash [^/\\\\]#
} 4. end of line (#e)

It's in the block in pattern.c:patchmatch() that begins with the
comment:

		/*
		 * Lookahead to avoid useless matches. This is not possible
		 * with approximation.
		 */

Specifically, in the "if (no >= min) for (;;) ..." loop, at each charater
in the input string patmatch() is called recursively to look at the rest
of the string, which again enters this same loop because the next thing
is also a one-or-more expression, which calls recursively and again
enters the loop because the thing after that is a zero-or-more.

It consumes a LOT of memory while doing this, even if I add a hack to
prevent it from recursively re-entering lookahead (or to skip the
lookahead entirely).