From a0f7d81a8dfefc20a283585dca3a37240a2b7a9a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Thu, 16 Jun 2022 16:04:48 +0200 Subject: [PATCH] * src/fns.c (mapcar1): Test types in rough order of likelyhood. --- src/fns.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/fns.c b/src/fns.c index 97af39c4161..4df944507c7 100644 --- a/src/fns.c +++ b/src/fns.c @@ -2757,20 +2757,26 @@ usage: (nconc &rest LISTS) */) static EMACS_INT mapcar1 (EMACS_INT leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq) { - if (VECTORP (seq) || COMPILEDP (seq)) + if (NILP (seq)) + return 0; + else if (CONSP (seq)) { + Lisp_Object tail = seq; for (ptrdiff_t i = 0; i < leni; i++) { - Lisp_Object dummy = call1 (fn, AREF (seq, i)); + if (! CONSP (tail)) + return i; + Lisp_Object dummy = call1 (fn, XCAR (tail)); if (vals) vals[i] = dummy; + tail = XCDR (tail); } } - else if (BOOL_VECTOR_P (seq)) + else if (VECTORP (seq) || COMPILEDP (seq)) { - for (EMACS_INT i = 0; i < leni; i++) + for (ptrdiff_t i = 0; i < leni; i++) { - Lisp_Object dummy = call1 (fn, bool_vector_ref (seq, i)); + Lisp_Object dummy = call1 (fn, AREF (seq, i)); if (vals) vals[i] = dummy; } @@ -2788,17 +2794,14 @@ mapcar1 (EMACS_INT leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq) vals[i_before] = dummy; } } - else /* Must be a list, since Flength did not get an error */ + else { - Lisp_Object tail = seq; - for (ptrdiff_t i = 0; i < leni; i++) + eassert (BOOL_VECTOR_P (seq)); + for (EMACS_INT i = 0; i < leni; i++) { - if (! CONSP (tail)) - return i; - Lisp_Object dummy = call1 (fn, XCAR (tail)); + Lisp_Object dummy = call1 (fn, bool_vector_ref (seq, i)); if (vals) vals[i] = dummy; - tail = XCDR (tail); } } -- 2.39.2