about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatt Beshara <m@mfa.pw>2021-09-06T04·46+1000
committerAdrián Medraño Calvo <adrian@medranocalvo.com>2021-10-25T16·05-0400
commit182ffbed6c7334ee51cb5cd2645ba0ee42c4da13 (patch)
tree788b26f4bdb1a88217cca10dd87b2256f20866f3
parent1863361674159431d09140375d14c44f17a6608d (diff)
Use a hash table to cache result of ‘exwm-workspace--client-p’
* exwm-workspace.el (exwm--client-p-hash-table): New variable.
(exwm-workspace--client-p): Use `exwm--client-p-hash-table' to
store which workspace frames are client frames instead of
frequently invoking `frame-parameter'.
-rw-r--r--exwm-workspace.el13
1 files changed, 11 insertions, 2 deletions
diff --git a/exwm-workspace.el b/exwm-workspace.el
index cff17f3a113a..c1de5da9a391 100644
--- a/exwm-workspace.el
+++ b/exwm-workspace.el
@@ -165,10 +165,19 @@ NIL if FRAME is not a workspace"
   "Return t if FRAME is a workspace."
   (memq frame exwm-workspace--list))
 
+(defvar exwm--client-p-hash-table
+  (make-hash-table :test 'eq :weakness 'key))
+
 (defsubst exwm-workspace--client-p (&optional frame)
   "Return non-nil if FRAME is an emacsclient frame."
-  (or (frame-parameter frame 'client)
-      (not (display-graphic-p frame))))
+  (let* ((frame (or frame (selected-frame)))
+         (cached-value (gethash frame exwm--client-p-hash-table 'absent)))
+    (if (eq cached-value 'absent)
+        (puthash frame
+                 (or (frame-parameter frame 'client)
+                     (not (display-graphic-p frame)))
+                 exwm--client-p-hash-table)
+        cached-value)))
 
 (defvar exwm-workspace--switch-map nil
   "Keymap used for interactively selecting workspace.")