From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines Date: Thu, 12 Jan 2017 14:32:02 +0900 (JST) Message-ID: References: <8737grz0q3.fsf@gmail.com> <8737gr0zbn.fsf@users.sourceforge.net> <87fukqe2eu.fsf@gmail.com> <8760lmqak1.fsf@gmail.com> <87wpe0zz0s.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Trace: blaine.gmane.org 1484199199 6300 195.159.176.226 (12 Jan 2017 05:33:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 12 Jan 2017 05:33:19 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) Cc: 25410@debbugs.gnu.org To: npostavs@users.sourceforge.net Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jan 12 06:33:14 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRY0b-0000PY-B4 for geb-bug-gnu-emacs@m.gmane.org; Thu, 12 Jan 2017 06:33:09 +0100 Original-Received: from localhost ([::1]:59786 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRY0d-0008H3-RP for geb-bug-gnu-emacs@m.gmane.org; Thu, 12 Jan 2017 00:33:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRY0X-0008Gy-7V for bug-gnu-emacs@gnu.org; Thu, 12 Jan 2017 00:33:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cRY0U-0002YD-2Y for bug-gnu-emacs@gnu.org; Thu, 12 Jan 2017 00:33:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:35211) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cRY0T-0002Y9-VA for bug-gnu-emacs@gnu.org; Thu, 12 Jan 2017 00:33:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cRY0T-0006iJ-Lx for bug-gnu-emacs@gnu.org; Thu, 12 Jan 2017 00:33:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 Jan 2017 05:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25410 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 25410-submit@debbugs.gnu.org id=B25410.148419913325737 (code B ref 25410); Thu, 12 Jan 2017 05:33:01 +0000 Original-Received: (at 25410) by debbugs.gnu.org; 12 Jan 2017 05:32:13 +0000 Original-Received: from localhost ([127.0.0.1]:50610 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRXzh-0006h3-6n for submit@debbugs.gnu.org; Thu, 12 Jan 2017 00:32:13 -0500 Original-Received: from mail-pf0-f175.google.com ([209.85.192.175]:36008) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRXzf-0006go-2u for 25410@debbugs.gnu.org; Thu, 12 Jan 2017 00:32:11 -0500 Original-Received: by mail-pf0-f175.google.com with SMTP id 189so6762991pfu.3 for <25410@debbugs.gnu.org>; Wed, 11 Jan 2017 21:32:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=TVNfhCDRtbcZ75U/w+7qd9GPlWZm45Nk6BJP/e4t218=; b=KPCE5rMEveWJYjn/7+5rlDr7JmuWuPBsspQvPwaA6MEx37CMMJCPRKzkd4LcXRykES 4pq48eFENYLFf2xX5ddnTA4s078XoVJ7rrnUKe1gEwvZB2y9qPzIbNcCBGBrpj5Up+vQ 2TRDmEKx9zOLNhkrq4Bgj3IIjdMKUcD0XkHsTZKGe/O0NTFI3Y2czkfPCwTwqgdMzMdd lhyvkDyAttOTkCxY7mkSAue3gc4z7MhcObDQvV8yvqa51vEzBAyUqeckdzL65/2uVtdU rmGJMD3+ZIEd1gBPgrE27EVwLaiQKIe++vNuiyjnO5BW6JgP+zg2vZTTniQgY/COdTYK jn5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=TVNfhCDRtbcZ75U/w+7qd9GPlWZm45Nk6BJP/e4t218=; b=edRKGGFg488G+W46yJPLbvfXv5m3y8sQ3roVofhaQzwWqpt/MSVAKzP8rBGnJqSPKW i3eT2iNn/oDa1NVnMEIdrVd4zOllzzligqphzrcFx0F+uhmHB+kn8FWpPb1/78i2ug7f 5sgTHOE5jg8ZSLM4vOIx1nTfHcZnicfGa2r79yWZ4Qi/mYAjVJAM5o6j2DzZFtaeqcGx u38PjDOb8ZbLq+3s1/B/yp5eRjD2/pdJKqUD6KGbmXV52BLWm6vZqfzfwJI6622dEiXe ZoaGgAAtqqf6AznqdIVF2vFbMcJHSgsXB7kDurDwbRlyGjv+3KOAG07CZ05wjIEWvTp/ PIBQ== X-Gm-Message-State: AIkVDXLEjV/mwIDLh1pKhLc8n/7YOqU1O3RVV6byALpEkFf2bWuCErNvnEkfDPJPZeWjzg== X-Received: by 10.98.208.70 with SMTP id p67mr14705961pfg.15.1484199125183; Wed, 11 Jan 2017 21:32:05 -0800 (PST) Original-Received: from calancha-pc (217.225.128.101.dy.bbexcite.jp. [101.128.225.217]) by smtp.gmail.com with ESMTPSA id 64sm17692017pfu.17.2017.01.11.21.32.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jan 2017 21:32:04 -0800 (PST) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc In-Reply-To: <87wpe0zz0s.fsf@users.sourceforge.net> 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: 208.118.235.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:128031 Archived-At: On Wed, 11 Jan 2017, npostavs@users.sourceforge.net wrote: > Tino Calancha writes: > >> From a performance point of view, current code in the case where >> the hunk just adds lines is not as patological as the opposite one. >> M-! git diff ef8c9f8^ ef8c9f8 RET > > By the way, with Emacs 25.1, I notice trying to refine this gives me a > regex stack overflow error. Probably my recent changes to the regex > stack limits allow Emacs to spend more time on this instead of > overflowing. Yeah, your commit has revealed such nasty regexp's. Before we get a stack overflow and the refine of the hunk ends. >> We might use the first patch in this thread or the following one: > > It's probably okay to use the first patch (i.e., don't bother checking > for delete-only hunks), with an added comment about the asymmetry. But > I think it would be better to change diff-refine-hunk to avoid the > inefficient regex, like this: I agree with you it's better to not use such heavy regexp matching too many lines. Your patch LGTM. Thank very much. >>From f5ea9e585b535390a69e442d83ecbeec8e8e18d2 Mon Sep 17 00:00:00 2001 >From: Noam Postavsky >Date: Wed, 11 Jan 2017 23:21:38 -0500 >Subject: [PATCH v1] Avoid inefficient regex in diff-refine-hunk (Bug#25410) > >* lisp/vc/diff-mode.el (diff--forward-while-leading-char): New function. >(diff-refine-hunk): Use it instead of trying to match multiple lines >with a single lines. >--- > lisp/vc/diff-mode.el | 27 +++++++++++++++++---------- > 1 file changed, 17 insertions(+), 10 deletions(-) > >diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el >index 9dfcd94..915e0b1 100644 >--- a/lisp/vc/diff-mode.el >+++ b/lisp/vc/diff-mode.el >@@ -2062,6 +2062,15 @@ diff-refine-preproc > (declare-function smerge-refine-subst "smerge-mode" > (beg1 end1 beg2 end2 props-c &optional preproc props-r props-a)) > >+(defun diff--forward-while-leading-char (char bound) >+ "Move point until reaching a line not starting with CHAR. >+Return new point, if it was moved." >+ (let ((pt nil)) >+ (while (and (< (point) bound) (eql (following-char) char)) >+ (forward-line 1) >+ (setq pt (point))) >+ pt)) >+ > (defun diff-refine-hunk () > "Highlight changes of hunk at point at a finer granularity." > (interactive) >@@ -2081,16 +2090,14 @@ diff-refine-hunk > (goto-char beg) > (pcase style > (`unified >- (while (re-search-forward >- (eval-when-compile >- (let ((no-LF-at-eol-re "\\(?:\\\\.*\n\\)?")) >- (concat "^\\(?:-.*\n\\)+" no-LF-at-eol-re >- "\\(\\)" >- "\\(?:\\+.*\n\\)+" no-LF-at-eol-re))) >- end t) >- (smerge-refine-subst (match-beginning 0) (match-end 1) >- (match-end 1) (match-end 0) >- nil 'diff-refine-preproc props-r props-a))) >+ (while (re-search-forward "^-" end t) >+ (let ((beg-del (progn (beginning-of-line) (point))) >+ beg-add end-add) >+ (when (and (setq beg-add (diff--forward-while-leading-char ?- end)) >+ (or (diff--forward-while-leading-char ?\\ end) t) >+ (setq end-add (diff--forward-while-leading-char ?+ end))) >+ (smerge-refine-subst beg-del beg-add beg-add end-add >+ nil 'diff-refine-preproc props-r props-a))))) > (`context > (let* ((middle (save-excursion (re-search-forward "^---"))) > (other middle)) >-- >2.9.3 >