Reorder type tests for efficiency
* src/fns.c (Flength, Fdelete, Fnreverse): Test types in descending order of frequency, roughly.
This commit is contained in:
parent
054fc8a5e0
commit
a82785e297
1 changed files with 28 additions and 24 deletions
52
src/fns.c
52
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue