Subject: Re: bug#18522: 24.4.50; mapcar is very slow

From: martin rudalics <[email-masked]>
Date: Thu, 25 Feb 2016 11:06:32 +0100

> Could you provide some code please, to show the names?

Try ‘killed-buffer-names’ from the attached patch.

martin
diff --git a/src/buffer.c b/src/buffer.c
index 653e3fe..c8cec8c 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -287,6 +287,8 @@ static void
 bset_name (struct buffer *b, Lisp_Object val)
 {
   b->name_ = val;
+  if (!NILP (val))
+    b->live_name_ = val;
 }
 static void
 bset_overwrite_mode (struct buffer *b, Lisp_Object val)
@@ -415,6 +417,21 @@ followed by the rest of the buffers.  */)
     return general;
 }

+DEFUN ("killed-buffer-names", Fkilled_buffer_names, Skilled_buffers_names, 0, 0, 0,
+       doc: /* Return list of names of killed buffers that have not been recycled yet.  */)
+  ()
+{
+  struct buffer *b;
+  Lisp_Object val = Qnil;
+
+  FOR_EACH_BUFFER (b)
+    if (NILP (b->name_))
+      val = Fcons (b->live_name_, val);
+
+  return val;
+}
+
+
 /* Like Fassoc, but use Fstring_equal to compare
    (which ignores text properties),
    and don't ever QUIT.  */
@@ -1103,6 +1120,14 @@ Return nil if BUFFER has been killed.  */)
   return BVAR (decode_buffer (buffer), name);
 }

+DEFUN ("buffer-live-name", Fbuffer_live_name, Sbuffer_live_name, 0, 1, 0,
+       doc: /* Return the name of BUFFER when it was live, as a string.
+	       BUFFER defaults to the current buffer.  */)
+  (register Lisp_Object buffer)
+{
+  return BVAR (decode_buffer (buffer), live_name);
+}
+
 DEFUN ("buffer-file-name", Fbuffer_file_name, Sbuffer_file_name, 0, 1, 0,
        doc: /* Return name of file BUFFER is visiting, or nil if none.
 No argument or nil as argument means use the current buffer.  */)
@@ -6278,12 +6303,14 @@ Functions running this hook are, `get-buffer-create',

   defsubr (&Sbuffer_live_p);
   defsubr (&Sbuffer_list);
+  defsubr (&Skilled_buffers_names);
   defsubr (&Sget_buffer);
   defsubr (&Sget_file_buffer);
   defsubr (&Sget_buffer_create);
   defsubr (&Smake_indirect_buffer);
   defsubr (&Sgenerate_new_buffer_name);
   defsubr (&Sbuffer_name);
+  defsubr (&Sbuffer_live_name);
   defsubr (&Sbuffer_file_name);
   defsubr (&Sbuffer_base_buffer);
   defsubr (&Sbuffer_local_value);
diff --git a/src/buffer.h b/src/buffer.h
index 5783bfb..24bbcb3 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -500,6 +500,9 @@ struct buffer
   /* The name of this buffer.  */
   Lisp_Object name_;

+  /* The name of this buffer when it was live.  */
+  Lisp_Object live_name_;
+
   /* The name of the file visited in this buffer, or nil.  */
   Lisp_Object filename_;