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#35418: [PATCH] Don't poll auto-revert files that use notification Date: Mon, 29 Apr 2019 20:29:07 +0200 Message-ID: References: <83sgu71b91.fsf@gnu.org> <74CB5185-5DA1-4786-BD9C-9EEB3D43B3C1@acm.org> <83o94uz9h2.fsf@gnu.org> <875zqzssql.fsf@gmx.de> <83d0l7v193.fsf@gnu.org> <86EFE367-90FF-4786-BC91-FC28FAF38A4E@acm.org> <877ebdqmbj.fsf@gmx.de> <87imuxxawj.fsf@gmx.de> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_562E6D03-ACA9-4D83-8308-BCD7690D009F" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="188885"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 35418@debbugs.gnu.org To: Michael Albinus Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Apr 29 20:30:15 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.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hLB2Z-000mwv-Qe for geb-bug-gnu-emacs@m.gmane.org; Mon, 29 Apr 2019 20:30:12 +0200 Original-Received: from localhost ([127.0.0.1]:33539 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLB2Y-0001NF-R2 for geb-bug-gnu-emacs@m.gmane.org; Mon, 29 Apr 2019 14:30:10 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:54109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLB2S-0001My-8B for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 14:30:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLB2R-0004uI-Bi for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 14:30:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54373) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hLB2R-0004to-1D for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 14:30:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hLB2Q-0004EI-4X for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 14:30:02 -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: Mon, 29 Apr 2019 18:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35418 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 35418-submit@debbugs.gnu.org id=B35418.155656255316175 (code B ref 35418); Mon, 29 Apr 2019 18:30:02 +0000 Original-Received: (at 35418) by debbugs.gnu.org; 29 Apr 2019 18:29:13 +0000 Original-Received: from localhost ([127.0.0.1]:39684 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLB1c-0004Co-Pk for submit@debbugs.gnu.org; Mon, 29 Apr 2019 14:29:13 -0400 Original-Received: from mail232c50.megamailservers.eu ([91.136.10.242]:53204 helo=mail37c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLB1b-0004Ce-4r for 35418@debbugs.gnu.org; Mon, 29 Apr 2019 14:29:12 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1556562549; bh=S0GliIX+CAKhnH13nTr8m+jJEpY23gh4jxlqgXDDCPw=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=MK38lNpY7EUL1Vpt7xNWFlLinKvJytEpwPtePycr5lalx5doTZ00k///eubW0HS0v Vg/vwmE+3GhPwcHBB3B1SSoDAqQUsUlBQK4g3M0fPFPxGGYsXyDbn/eqoxa2+qvc+3 dN+cnI9E0pmM4/ZzwbR7Lmcj9OUqw3BBv+GjIdiM= 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 mail37c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id x3TIT7GD014355; Mon, 29 Apr 2019 18:29:08 +0000 In-Reply-To: <87imuxxawj.fsf@gmx.de> X-Mailer: Apple Mail (2.3445.104.8) X-CTCH-RefID: str=0001.0A0B020A.5CC74275.003B, 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=QrpwI26d c=1 sm=1 tr=0 a=M+GU/qJco4WXjv8D6jB2IA==:117 a=M+GU/qJco4WXjv8D6jB2IA==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=f1abiShv9wPjO9RxvYYA:9 a=CjuIK1q_8ugA:10 a=q6jAsax-SiwqlBvZBbQA:9 a=B2y7HmGcmWMA: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:158440 Archived-At: --Apple-Mail=_562E6D03-ACA9-4D83-8308-BCD7690D009F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 29 apr. 2019 kl. 14.18 skrev Michael Albinus : >=20 >> I decided to maintain it as a derived state >> because it felt silly to replace O(1) code with O(N), and the >> invariant is clear enough (stated in its doc string). (Some of the >> places where the variable is updated are O(N) but less frequently >> executed.) >=20 > Yes, but is N large enough to experience the difference? These things are tricky to measure, but obviously inefficient code just = doesn't feel right to write. For example, generating a list just to see = if it is non-empty, when that could be determined in a more = straightforward way. > My proposal was to use it NOT as a predicate, but as a function > returning the buffer list. Very well; here is an incremental patch (to make the differences clear). = It's a compromise: the derived state is gone, but there are two = functions: one for the list of buffers that need to be polled, and one = for whether that list would be non-empty. By the way, the patch now uses functions from cl-lib, not just macros. = Is there any reason not to? --Apple-Mail=_562E6D03-ACA9-4D83-8308-BCD7690D009F Content-Disposition: attachment; filename=0001-Eliminate-the-auto-revert-polled-buffers-variable.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Eliminate-the-auto-revert-polled-buffers-variable.patch" Content-Transfer-Encoding: quoted-printable =46rom=20e3fe91d6b760b8325c352e6220997f569f7f2d44=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Mon,=2029=20Apr=202019=2020:21:32=20+0200=0A= Subject:=20[PATCH]=20Eliminate=20the=20auto-revert--polled-buffers=20= variable=0A=0AInstead=20of=20maintaining=20the=20= `auto-revert--polled-buffers'=20variable,=0Acalculate=20it=20when=20= needed.=20=20When=20only=20its=20emptiness=20is=20of=20interest,=0Ado=20= so=20in=20a=20more=20efficient=20way.=0A---=0A=20lisp/autorevert.el=20|=20= 46=20++++++++++++++++++++++------------------------=0A=201=20file=20= changed,=2022=20insertions(+),=2024=20deletions(-)=0A=0Adiff=20--git=20= a/lisp/autorevert.el=20b/lisp/autorevert.el=0Aindex=20= b16b1b5833..6387ef1e92=20100644=0A---=20a/lisp/autorevert.el=0A+++=20= b/lisp/autorevert.el=0A@@=20-107,7=20+107,7=20@@=0A=20=0A=20;;=20= Dependencies:=0A=20=0A-(eval-when-compile=20(require=20'cl-lib))=0A= +(require=20'cl-lib)=0A=20(require=20'timer)=0A=20(require=20= 'filenotify)=0A=20=0A@@=20-342,11=20+342,6=20@@=20the=20list=20of=20old=20= buffers.")=0A=20(defvar=20auto-revert-tail-pos=200=0A=20=20=20"Position=20= of=20last=20known=20end=20of=20file.")=0A=20=0A-(defvar=20= auto-revert--polled-buffers=20()=0A-=20=20"List=20of=20buffers=20in=20= Auto-Revert=20Mode=20that=20must=20be=20polled.=0A-It=20contains=20the=20= buffers=20in=20`auto-revert-buffer-list'=20whose=0A= -`auto-revert-notify-watch-descriptor'=20is=20nil.")=0A-=0A=20(defun=20= auto-revert-find-file-function=20()=0A=20=20=20(setq-local=20= auto-revert-tail-pos=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (file-attribute-size=20(file-attributes=20buffer-file-name))))=0A@@=20= -374,12=20+369,8=20@@=20This=20has=20been=20reported=20by=20a=20file=20= notification=20event.")=0A=20(defun=20auto-revert-remove-current-buffer=20= (&optional=20buffer)=0A=20=20=20"Remove=20BUFFER=20from=20= `auto-revert-buffer-list'.=0A=20BUFFER=20defaults=20to=20= `current-buffer'."=0A-=20=20(unless=20buffer=0A-=20=20=20=20(setq=20= buffer=20(current-buffer)))=0A=20=20=20(setq=20auto-revert-buffer-list=0A= -=20=20=20=20=20=20=20=20(delq=20buffer=20auto-revert-buffer-list))=0A-=20= =20(setq=20auto-revert--polled-buffers=0A-=20=20=20=20=20=20=20=20(delq=20= buffer=20auto-revert--polled-buffers)))=0A+=20=20=20=20=20=20=20=20(delq=20= (or=20buffer=20(current-buffer))=20auto-revert-buffer-list)))=0A=20=0A=20= ;;;###autoload=0A=20(define-minor-mode=20auto-revert-mode=0A@@=20-399,7=20= +390,6=20@@=20without=20being=20changed=20in=20the=20part=20that=20is=20= already=20in=20the=20buffer."=0A=20=20=20(if=20auto-revert-mode=0A=20=20=20= =20=20=20=20(when=20(not=20(memq=20(current-buffer)=20= auto-revert-buffer-list))=0A=20=20=20=20=20=20=20=20=20(push=20= (current-buffer)=20auto-revert-buffer-list)=0A-=20=20=20=20=20=20=20=20= (push=20(current-buffer)=20auto-revert--polled-buffers)=0A=20=20=20=20=20= =20=20=20=20(add-hook=0A=20=20=20=20=20=20=20=20=20=20'kill-buffer-hook=0A= =20=20=20=20=20=20=20=20=20=20#'auto-revert-remove-current-buffer=0A@@=20= -516,12=20+506,26=20@@=20specifies=20in=20the=20mode=20line."=0A=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(not=20(memq=20buf=20= auto-revert-buffer-list)))=0A=20=09=20=20= (auto-revert-notify-rm-watch))))))=0A=20=0A+(defun=20= auto-revert--polled-buffers=20()=0A+=20=20"List=20of=20buffers=20that=20= need=20to=20be=20polled."=0A+=20=20(cond=20(global-auto-revert-mode=20= (buffer-list))=0A+=20=20=20=20=20=20=20=20(auto-revert-always-poll=20= auto-revert-buffer-list)=0A+=20=20=20=20=20=20=20=20(t=20(mapcan=20= (lambda=20(buffer)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20(and=20(not=20(buffer-local-value=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= 'auto-revert-notify-watch-descriptor=20buffer))=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(list=20buffer)))=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= auto-revert-buffer-list))))=0A+=0A+;;=20Same=20as=20above=20in=20a=20= boolean=20context,=20but=20cheaper.=0A=20(defun=20= auto-revert--need-polling-p=20()=0A=20=20=20"Whether=20periodic=20= polling=20is=20required."=0A=20=20=20(or=20global-auto-revert-mode=0A=20=20= =20=20=20=20=20(if=20auto-revert-always-poll=0A=20=20=20=20=20=20=20=20=20= =20=20auto-revert-buffer-list=0A-=20=20=20=20=20=20=20=20= auto-revert--polled-buffers)))=0A+=20=20=20=20=20=20=20=20(not=20= (cl-every=20(lambda=20(buffer)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20(buffer-local-value=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= 'auto-revert-notify-watch-descriptor=20buffer))=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= auto-revert-buffer-list)))))=0A=20=0A=20(defun=20auto-revert-set-timer=20= ()=0A=20=20=20"Restart=20or=20cancel=20the=20timer=20used=20by=20= Auto-Revert=20Mode.=0A@@=20-592,8=20+596,6=20@@=20will=20use=20an=20= up-to-date=20value=20of=20`auto-revert-interval'"=0A=20=09=20=20=20=20=20= =20=20(gethash=20auto-revert-notify-watch-descriptor=0A=20=09=09=20=20=20= =20=20=20=20=20auto-revert--buffers-by-watch-descriptor))=0A=20=20=20=20=20= =20=20=20=20=20auto-revert--buffers-by-watch-descriptor)=0A-=20=20=20=20=20= =20=20=20(setq=20auto-revert--polled-buffers=0A-=20=20=20=20=20=20=20=20=20= =20=20=20=20=20(delq=20(current-buffer)=20auto-revert--polled-buffers))=0A= =20=20=20=20=20=20=20=20=20(add-hook=20'kill-buffer-hook=20= #'auto-revert-notify-rm-watch=20nil=20t)))))=0A=20=0A=20;;=20If=20we=20= have=20file=20notifications,=20we=20want=20to=20update=20the=20= auto-revert=20buffers=0A@@=20-644,12=20+646,10=20@@=20system.")=0A=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20;;=20A=20buffer=20= w/o=20a=20file,=20like=20dired.=0A=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20(null=20buffer-file-name))=0A=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20(auto-revert-notify-rm-watch)=0A-=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20(when=20(memq=20buffer=20= auto-revert-buffer-list)=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20(unless=20(memq=20buffer=20auto-revert--polled-buffers)=0A-=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(push=20buffer=20= auto-revert--polled-buffers))=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20;;=20Restart=20the=20timer=20if=20it=20wasn't=20running.=0A-=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(unless=20= auto-revert-timer=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20(auto-revert-set-timer))))))=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20;;=20Restart=20the=20timer=20if=20it=20wasn't=20running.=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(when=20(and=20(memq=20= buffer=20auto-revert-buffer-list)=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(not=20auto-revert-timer))=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (auto-revert-set-timer)))))=0A=20=0A=20=20=20=20=20=20=20=20=20;;=20Loop=20= over=20all=20buffers,=20in=20order=20to=20find=20the=20intended=20one.=0A= =20=20=20=20=20=20=20=20=20(cl-dolist=20(buffer=20buffers)=0A@@=20-811,9=20= +811,7=20@@=20Auto-Revert=20Mode=20from=20`auto-revert-buffer-list',=20= and=20for=20canceling=0A=20the=20timer=20when=20no=20buffers=20need=20to=20= be=20checked."=0A=20=0A=20=20=20(save-match-data=0A-=20=20=20=20(let=20= ((bufs=20(cond=20(global-auto-revert-mode=20(buffer-list))=0A-=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (auto-revert-always-poll=20auto-revert-buffer-list)=0A-=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(t=20= auto-revert--polled-buffers)))=0A+=20=20=20=20(let=20((bufs=20= (auto-revert--polled-buffers))=0A=20=09=20=20remaining=20new)=0A=20=20=20= =20=20=20=20;;=20Buffers=20with=20remote=20contents=20shall=20be=20= reverted=20only=20if=20the=0A=20=20=20=20=20=20=20;;=20connection=20is=20= established=20already.=0A--=20=0A2.20.1=20(Apple=20Git-117)=0A=0A= --Apple-Mail=_562E6D03-ACA9-4D83-8308-BCD7690D009F--