From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#36444: [PATCH] Improved regexp-opt KEEP-ORDER check Date: Thu, 4 Jul 2019 13:52:31 +0200 Message-ID: <74D2BB46-AE27-4F7B-8E76-E12527834B53@acm.org> References: <2CE5D98F-8F07-4E79-9132-FDBA0062D8E2@acm.org> <85v9wiex2a.fsf@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="5699"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 36444@debbugs.gnu.org To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 04 13:53:14 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hj0Ib-0001Lv-LX for geb-bug-gnu-emacs@m.gmane.org; Thu, 04 Jul 2019 13:53:13 +0200 Original-Received: from localhost ([::1]:44730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hj0Ia-0004Vo-Bw for geb-bug-gnu-emacs@m.gmane.org; Thu, 04 Jul 2019 07:53:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35240) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hj0IR-0004Vf-JJ for bug-gnu-emacs@gnu.org; Thu, 04 Jul 2019 07:53:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hj0IQ-0006Gr-Le for bug-gnu-emacs@gnu.org; Thu, 04 Jul 2019 07:53:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41661) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hj0IP-0006GA-V8 for bug-gnu-emacs@gnu.org; Thu, 04 Jul 2019 07:53:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hj0IP-0007nU-Rz for bug-gnu-emacs@gnu.org; Thu, 04 Jul 2019 07:53:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 04 Jul 2019 11:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36444 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 36444-submit@debbugs.gnu.org id=B36444.156224116529947 (code B ref 36444); Thu, 04 Jul 2019 11:53:01 +0000 Original-Received: (at 36444) by debbugs.gnu.org; 4 Jul 2019 11:52:45 +0000 Original-Received: from localhost ([127.0.0.1]:50482 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hj0I9-0007mx-8z for submit@debbugs.gnu.org; Thu, 04 Jul 2019 07:52:45 -0400 Original-Received: from mail1424c50.megamailservers.eu ([91.136.14.24]:51286 helo=mail102c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hj0I6-0007mh-8s for 36444@debbugs.gnu.org; Thu, 04 Jul 2019 07:52:44 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1562241155; bh=+4tXxyZVO7DgP6gRY8PENsDc32I4gDC1mi+mJPMfPVg=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=j7mSigOO/K+ukCuhbuU4wJrr76JvNsN8Z0iL4v4nuxDrK1A/eFZ9AF0//gEr0tKXs NhLa7Jyj/Jz3AYOiaK7/Wy6AlkRON8DDhLNa0i2pXyxBlId+oh4kw5Y20qrSVa/voE p1TqLQuolTYbXzRXdQ0aQjt21hvxRaODivfrDEbA= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.1.64] (c-e636e253.032-75-73746f71.bbcust.telenor.se [83.226.54.230]) (authenticated bits=0) by mail102c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id x64BqWMQ025112; Thu, 4 Jul 2019 11:52:34 +0000 In-Reply-To: <85v9wiex2a.fsf@gmail.com> X-Mailer: Apple Mail (2.3445.104.11) X-CTCH-RefID: str=0001.0A0B0205.5D1DE883.0036, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=RfS+9Wlv c=1 sm=1 tr=0 a=M+GU/qJco4WXjv8D6jB2IA==:117 a=M+GU/qJco4WXjv8D6jB2IA==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=kj9zAlcOel0A:10 a=pGLkceISAAAA:8 a=IKg0c7FWY9yppsr4vyAA:9 a=wXfZdyDHUFKTr466:21 a=z7UTTEmDI5PgOhj1:21 a=CjuIK1q_8ugA:10 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:162045 Archived-At: 3 juli 2019 kl. 21.29 skrev Noam Postavsky : >=20 > You don't actually need this save-match-data, right? Because there is > already one at the top level of the function (which I'm also not sure = is > really needed, but probably best not to touch that). Thank you! I don't know how I missed the existing save-match-data. = Removed. > IMO, a dolist + catch & throw would be a bit more readable; it took me > some puzzling to realize that the early exit was the "non-optimized" > case. >=20 > (and keep-order > (let* ((case-fold-search nil) > (alts (mapconcat #'regexp-quote strings "\\|"))) > (and (catch 'has-prefix > (dolist (s strings) > (unless (and (string-match alts s) > (=3D (match-end 0) (length s))) > (throw 'has-prefix s)))) > (concat (or open "\\(?:") alts "\\)")))) Not too fond of that either, really; catch/throw somehow seems more = heavyweight than warranted by the situation. Initially I used cl-every, but ran into the usual bootstrap problems. Here are two alternatives: (1) Same as before, but with a comment about what tripped you up: > (and (let ((s strings)) > (while (and s > (string-match alts (car s)) > (=3D (match-end 0) (length (car s)))) > (setq s (cdr s))) > ;; If we exited early, we found evidence that > ;; regexp-opt-group cannot be used. > s) > (concat (or open "\\(?:") alts "\\)"))))) (2) Using cl-loop: > (and (not (cl-loop > for s in strings > always (and (string-match alts s) > (=3D (match-end 0) (length s))))) > (concat (or open "\\(?:") alts "\\)")))))