From: Mattias EngdegÄrd Date: Wed, 20 Sep 2023 08:34:12 +0000 (+0200) Subject: Reorder type tests for efficiency X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a82785e29785f070465c5db10953ecebca49e257;p=emacs.git Reorder type tests for efficiency * src/fns.c (Flength, Fdelete, Fnreverse): Test types in descending order of frequency, roughly. --- diff --git a/src/fns.c b/src/fns.c index 4731e416125..a3f89637dfd 100644 --- a/src/fns.c +++ b/src/fns.c @@ -141,6 +141,10 @@ efficient. */) if (STRINGP (sequence)) val = SCHARS (sequence); + else if (CONSP (sequence)) + val = list_length (sequence); + else if (NILP (sequence)) + val = 0; else if (VECTORP (sequence)) val = ASIZE (sequence); else if (CHAR_TABLE_P (sequence)) @@ -149,10 +153,6 @@ efficient. */) val = bool_vector_size (sequence); else if (COMPILEDP (sequence) || RECORDP (sequence)) val = PVSIZE (sequence); - else if (CONSP (sequence)) - val = list_length (sequence); - else if (NILP (sequence)) - val = 0; else wrong_type_argument (Qsequencep, sequence); @@ -2104,7 +2104,27 @@ changing the value of a sequence `foo'. See also `remove', which does not modify the argument. */) (Lisp_Object elt, Lisp_Object seq) { - if (VECTORP (seq)) + if (NILP (seq)) + ; + else if (CONSP (seq)) + { + Lisp_Object prev = Qnil, tail = seq; + + FOR_EACH_TAIL (tail) + { + if (!NILP (Fequal (elt, XCAR (tail)))) + { + if (NILP (prev)) + seq = XCDR (tail); + else + Fsetcdr (prev, XCDR (tail)); + } + else + prev = tail; + } + CHECK_LIST_END (tail, seq); + } + else if (VECTORP (seq)) { ptrdiff_t n = 0; ptrdiff_t size = ASIZE (seq); @@ -2193,23 +2213,7 @@ does not modify the argument. */) } } else - { - Lisp_Object prev = Qnil, tail = seq; - - FOR_EACH_TAIL (tail) - { - if (!NILP (Fequal (elt, XCAR (tail)))) - { - if (NILP (prev)) - seq = XCDR (tail); - else - Fsetcdr (prev, XCDR (tail)); - } - else - prev = tail; - } - CHECK_LIST_END (tail, seq); - } + wrong_type_argument (Qsequencep, seq); return seq; } @@ -2222,8 +2226,6 @@ This function may destructively modify SEQ to produce the value. */) { if (NILP (seq)) return seq; - else if (STRINGP (seq)) - return Freverse (seq); else if (CONSP (seq)) { Lisp_Object prev, tail, next; @@ -2263,6 +2265,8 @@ This function may destructively modify SEQ to produce the value. */) bool_vector_set (seq, size - i - 1, tem); } } + else if (STRINGP (seq)) + return Freverse (seq); else wrong_type_argument (Qarrayp, seq); return seq;