changeset 45237:3bb204606957

(intersection): Keep the elements of the returned list in the same order as in the first list.
author Andreas Schwab <schwab@suse.de>
date Sat, 11 May 2002 15:59:49 +0000
parents ebc4fa4ef475
children 193ea38d0029
files src/coding.c
diffstat 1 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/coding.c	Sat May 11 08:19:36 2002 +0000
+++ b/src/coding.c	Sat May 11 15:59:49 2002 +0000
@@ -6324,14 +6324,17 @@
 intersection (l1, l2)
      Lisp_Object l1, l2;
 {
-  Lisp_Object val;
-
-  for (val = Qnil; CONSP (l1); l1 = XCDR (l1))
+  Lisp_Object val = Fcons (Qnil, Qnil), tail;
+
+  for (tail = val; CONSP (l1); l1 = XCDR (l1))
     {
       if (!NILP (Fmemq (XCAR (l1), l2)))
-	val = Fcons (XCAR (l1), val);
+	{
+	  XSETCDR (tail, Fcons (XCAR (l1), Qnil));
+	  tail = XCDR (tail);
+	}
     }
-  return val;
+  return XCDR (val);
 }