From: Jim Porter <jporterbugs@gmail.com>
To: 51420@debbugs.gnu.org
Subject: bug#51420: 29.0.50; [PATCH] Be more efficient when checking for a matching client or frame in server.el
Date: Tue, 26 Oct 2021 13:18:05 -0700 [thread overview]
Message-ID: <ea6ee859-519e-6f89-7925-b2083403a4a2@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 884 bytes --]
Attached is a patch to eliminate unnecessary checks for matching
clients/frames in `server-handle-delete-frame' and
`server-kill-emacs-query-function'.
Previously, `server-handle-delete-frame' would iterate over all frames
to check if there were any other frames associated with the current
client. Now, it uses `seq-some' to stop iterating once it finds the
first such frame.
Similarly, `server-kill-emacs-query-function' used to iterate over all
clients, and then all buffers for *each* client to check if there were
any live buffers associated with any clients. Now, it uses a pair of
calls to `seq-some' to stop iterating once it finds a live buffer from
any client.
I haven't benchmarked these changes since I hope the strategy of
stopping iteration as soon as we can is uncontroversial. However, if you
think it's important, I can try to generate some benchmarks.
[-- Attachment #2: 0001-Be-more-efficient-when-checking-for-a-matching-clien.patch --]
[-- Type: text/plain, Size: 2307 bytes --]
From fdba88af916d8e47725da5aea52bb2ef45da09ef Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Tue, 26 Oct 2021 13:04:08 -0700
Subject: [PATCH] Be more efficient when checking for a matching client or
frame in server.el
lisp/server.el (server-handle-delete-frame): Use 'seq-some' to
determine if another frame for the current client exists.
(server-kill-emacs-query-function): Use 'seq-some' to determine if
another live client exists.
---
lisp/server.el | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/lisp/server.el b/lisp/server.el
index 5306a54776..478e59577e 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -485,11 +485,11 @@ server-handle-delete-frame
(when (and (frame-live-p frame)
proc
;; See if this is the last frame for this client.
- (>= 1 (let ((frame-num 0))
- (dolist (f (frame-list))
- (when (eq proc (frame-parameter f 'client))
- (setq frame-num (1+ frame-num))))
- frame-num)))
+ (not (seq-some
+ (lambda (f)
+ (and (not (eq frame f))
+ (eq proc (frame-parameter f 'client))))
+ (frame-list)))
(server-log (format "server-handle-delete-frame, frame %s" frame) proc)
(server-delete-client proc 'noframe)))) ; Let delete-frame delete the frame later.
@@ -1580,13 +1580,13 @@ server-done
(server-buffer-done (current-buffer))))
(defun server-kill-emacs-query-function ()
- "Ask before exiting Emacs if it has live clients."
- (or (not (let (live-client)
- (dolist (proc server-clients)
- (when (memq t (mapcar #'buffer-live-p
- (process-get proc 'buffers)))
- (setq live-client t)))
- live-client))
+ "Ask before exiting Emacs if it has live clients.
+A \"live client\" is a client with at least one live buffer
+associated with it."
+ (or (not (seq-some (lambda (proc)
+ (seq-some #'buffer-live-p
+ (process-get proc 'buffers)))
+ server-clients))
(yes-or-no-p "This Emacs session has clients; exit anyway? ")))
(defun server-kill-buffer ()
--
2.25.1
next reply other threads:[~2021-10-26 20:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-26 20:18 Jim Porter [this message]
2021-10-26 20:22 ` bug#51420: 29.0.50; [PATCH] Be more efficient when checking for a matching client or frame in server.el Jim Porter
2021-10-27 13:55 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ea6ee859-519e-6f89-7925-b2083403a4a2@gmail.com \
--to=jporterbugs@gmail.com \
--cc=51420@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.