]> git.eshelyaron.com Git - emacs.git/commitdiff
(buffer-local-set-state): Optimize away unused data
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 24 Mar 2025 21:08:26 +0000 (17:08 -0400)
committerEshel Yaron <me@eshelyaron.com>
Tue, 25 Mar 2025 18:18:53 +0000 (19:18 +0100)
* lisp/subr.el (buffer-local-set-state--get): Simplify by making it
take only the vars rather than the pairs.
(buffer-local-set-state): Adjust accordingly so we don't needlessly keep
part of the source code in the compiled code.

(cherry picked from commit e343055f63b7329292641d0bca7d03183f35d871)

lisp/subr.el

index a845e0451dc9000a4ee5a5274fc15a255e1158f9..7ccf1f938ec5a129ef42297ba5339dac6ad2c241 100644 (file)
@@ -259,20 +259,23 @@ in order to restore the state of the local variables set via this macro.
   (declare (debug setq))
   (unless (evenp (length pairs))
     (error "PAIRS must have an even number of variable/value members"))
-  `(prog1
-       (buffer-local-set-state--get ',pairs)
-     (setq-local ,@pairs)))
-
-(defun buffer-local-set-state--get (pairs)
+  (let ((vars nil)
+        (tmp pairs))
+    (while tmp (push (car tmp) vars) (setq tmp (cddr tmp)))
+    (setq vars (nreverse vars))
+    `(prog1
+         (buffer-local-set-state--get ',vars)
+       (setq-local ,@pairs))))
+
+(defun buffer-local-set-state--get (vars)
   (let ((states nil))
-    (while pairs
-      (push (list (car pairs)
-                  (and (boundp (car pairs))
-                       (local-variable-p (car pairs)))
-                  (and (boundp (car pairs))
-                       (symbol-value (car pairs))))
-            states)
-      (setq pairs (cddr pairs)))
+    (dolist (var vars)
+      (push (list var
+                  (and (boundp var)
+                       (local-variable-p var))
+                  (and (boundp var)
+                       (symbol-value var)))
+            states))
     (nreverse states)))
 
 (defun buffer-local-restore-state (states)