From a98d0daac473737da720c20f49f6f5abf36b074b Mon Sep 17 00:00:00 2001
From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Tue, 7 Feb 2023 13:16:40 +0100
Subject: [PATCH] Remove unnecessary cons in lexical eval

* src/eval.c (list_of_t): New.
(Feval): Use list_of_t instead of consing every time.
(syms_of_eval): Set list_of_t to (t) and staticpro it.
---
 src/eval.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/eval.c b/src/eval.c
index d42f7ffe894..e377e30c6fb 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -2348,6 +2348,8 @@ it defines a macro.  */)
 }
 
 
+static Lisp_Object list_of_t;  /* Never-modified constant containing (t).  */
+
 DEFUN ("eval", Feval, Seval, 1, 2, 0,
        doc: /* Evaluate FORM and return its value.
 If LEXICAL is t, evaluate using lexical scoping.
@@ -2357,7 +2359,7 @@ alist mapping symbols to their value.  */)
 {
   specpdl_ref count = SPECPDL_INDEX ();
   specbind (Qinternal_interpreter_environment,
-	    CONSP (lexical) || NILP (lexical) ? lexical : list1 (Qt));
+	    CONSP (lexical) || NILP (lexical) ? lexical : list_of_t);
   return unbind_to (count, eval_sub (form));
 }
 
@@ -4392,6 +4394,9 @@ alist of active lexical bindings.  */);
   Qcatch_all_memory_full
     = Fmake_symbol (build_pure_c_string ("catch-all-memory-full"));
 
+  staticpro (&list_of_t);
+  list_of_t = list1 (Qt);
+
   defsubr (&Sor);
   defsubr (&Sand);
   defsubr (&Sif);
-- 
2.39.5