From f570c0653ec9089c5fd6c01fdff1c20ad1fe5108 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Mon, 24 Mar 2025 17:08:26 -0400 Subject: [PATCH] (buffer-local-set-state): Optimize away unused data * 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 | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lisp/subr.el b/lisp/subr.el index a845e0451dc..7ccf1f938ec 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -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) -- 2.39.5