[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX-devel] Re: [AUCTeX-diffs] Changes to reftex/lisp/reftex-base.el,

From: David Kastrup
Subject: [AUCTeX-devel] Re: [AUCTeX-diffs] Changes to reftex/lisp/reftex-base.el, v
Date: Sat, 07 Jun 2008 14:17:58 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Ralf Angeli <address@hidden> writes:

> CVSROOT:      /sources/auctex
> Module name:  reftex
> Changes by:   Ralf Angeli <angeli>    08/06/07 11:17:14
> +(defun reftex-remove-if (predicate list)
> +  "Nondestructively remove all items from LIST which satisfy PREDICATE."
> +  (let (result)
> +    (dolist (elt list)
> +      (unless (funcall predicate elt)
> +     (add-to-list 'result elt t)))
> +    result))
> +

No, that's bad.  Since it also uniquifies the list.  add-to-list is an
O(n) operation, so this becomes O(n^2).

Try rather
(let (result)
  (dolist (elt list (nreverse result))
    (unless (funcall predicate elt)
      (push elt result))))

This is O(n).

David Kastrup, Kriemhildstr. 15, 44793 Bochum

reply via email to

[Prev in Thread] Current Thread [Next in Thread]