diff src/alloc.c @ 5386:af961911bcb2

Make listu() and listn() assemble lists in forward order. Use them. See xemacs-patches message with ID <AANLkTi=Tnd_e8WqiGBE2DmNGmY7zhqxhVNtxECnQo8w9@mail.gmail.com>
author Jerry James <james@xemacs.org>
date Tue, 29 Mar 2011 15:59:56 -0600
parents 3889ef128488
children 248176c74e6b
line wrap: on
line diff
--- a/src/alloc.c	Tue Mar 29 17:28:34 2011 +0100
+++ b/src/alloc.c	Tue Mar 29 15:59:56 2011 -0600
@@ -1465,18 +1465,23 @@
 listu (Lisp_Object first, ...)
 {
   Lisp_Object obj = Qnil;
-  Lisp_Object val;
-  va_list va;
-
-  va_start (va, first);
-  val = first;
-  while (!UNBOUNDP (val))
+
+  if (!UNBOUNDP (first))
     {
-      obj = Fcons (val, obj);
+      va_list va;
+      Lisp_Object last, val;
+
+      last = obj = Fcons (first, Qnil);
+      va_start (va, first);
       val = va_arg (va, Lisp_Object);
+      while (!UNBOUNDP (val))
+	{
+	  last = XCDR (last) = Fcons (val, Qnil);
+	  val = va_arg (va, Lisp_Object);
+	}
+      va_end (va);
     }
-  va_end (va);
-  return Fnreverse (obj);
+  return obj;
 }
 
 /* Return a list of arbitrary length, with length specified and remaining
@@ -1485,15 +1490,21 @@
 Lisp_Object
 listn (int num_args, ...)
 {
-  int i;
   Lisp_Object obj = Qnil;
-  va_list va;
-
-  va_start (va, num_args);
-  for (i = 0; i < num_args; i++)
-    obj = Fcons (va_arg (va, Lisp_Object), obj);
-  va_end (va);
-  return Fnreverse (obj);
+
+  if (num_args > 0)
+    {
+      va_list va;
+      Lisp_Object last;
+      int i;
+
+      va_start (va, num_args);
+      last = obj = Fcons (va_arg (va, Lisp_Object), Qnil);
+      for (i = 1; i < num_args; i++)
+	last = XCDR (last) = Fcons (va_arg (va, Lisp_Object), Qnil);
+      va_end (va);
+    }
+  return obj;
 }
 
 /* Return a list of arbitrary length, with length specified and an array