Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID
	autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=brasslantern-com.20150623.gappssmtp.com; s=20150623;
        h=from:message-id:date:in-reply-to:comments:references:to:subject
         :mime-version;
        bh=90SKtWiCUqe5g4cNoZ2N069erzItzxC0Rl7Rc2sMPGs=;
        b=NX0Ua1pOgQkKTX5WwIj2lvRuSEl4fsAU7A8UpDt+oy57ksNPZZd8BFqSQxfaSNQp+s
         oqgK/W6EiFahqoS/OJJQVXCQE6rDmEjbLLw/MbSv4J+AV2vFY80AMFh01qZOxc7U8IS6
         CXA69csyBxaKslXeY8ryfRcEjY0MWdK8k6RNpsRYdWLyCojgNIacAQjZaCy1ufyC6MJL
         z9ZSb2YiJUYWpc6uQLuazL7tn/ICbf4RPJR4zGquo09pMeyi+spM4dd0udVxP105YynN
         xs8Xvep0eU/kHizT5cfjKGY0amqMN+p9IJmZd8eQD2uwNH9/s6fw+3FK+q4cBQPkxe+q
         FV6g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:date:in-reply-to:comments
         :references:to:subject:mime-version;
        bh=90SKtWiCUqe5g4cNoZ2N069erzItzxC0Rl7Rc2sMPGs=;
        b=kJklfvMBvj56n9S9eRrnxC3U0oNo10jvs8UKKAMF9sMo7H5Q5rbSKvoQZnjyJivTY5
         jWU0oIYL4TrBlUtenwMlU8vtX91/X0d0xQs3Spex/Wgj8ExmF5W9RGC4aS4lkBxk5tEZ
         Pcl66itFOuVrNccx7/drzQpnaVJEOjC46UAO7WDYfqFN+Ez44piZVh/NNtb6H8sOX6Xk
         Qi/3pXbRePprjt1/NUfg4W5JaSwiPuPp0KtJq9hMqVBAcTqU4oY2DCVHjnqpi+ToM4s1
         xj07l9fZwz14bKeEmH3zslGCdBQ66o2O42EpK6ZxfAgyhJSAKED3sr/zw4+dDan5x/FC
         llzA==
X-Gm-Message-State: ALyK8tLfqTyiHAXyXVj911+VGeGn+AiLMUXK+hGWknP7it46lwslKNAuTMkqV63pqVZq5g==
X-Received: by 10.98.58.84 with SMTP id h81mr20710422pfa.93.1465153819343;
        Sun, 05 Jun 2016 12:10:19 -0700 (PDT)
From: Bart Schaefer <schaefer@brasslantern.com>
Message-Id: <160605121020.ZM7727@torch.brasslantern.com>
Date: Sun, 5 Jun 2016 12:10:20 -0700
In-Reply-To: <CAKc7PVC=AES1LhY7tYTXrPsefX3CXgtUsxiVbDaxmc5o2iHnVw@mail.gmail.com>
Comments: In reply to Sebastian Gniazdowski <sgniazdowski@gmail.com>
        "[BUG] Long line makes pattern matching (by //) hog Zsh" (Jun  5,  4:36pm)
References: <CAKc7PVC=AES1LhY7tYTXrPsefX3CXgtUsxiVbDaxmc5o2iHnVw@mail.gmail.com>
X-Mailer: OpenZMail Classic (0.9.2 24April2005)
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [BUG] Long line makes pattern matching (by //) hog Zsh
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Seq: zsh-workers 38616

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).

