emacs-devel
[Top][All Lists]
Advanced

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

Re: space leak from `values'


From: Kim F. Storm
Subject: Re: space leak from `values'
Date: 20 Aug 2004 14:51:32 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

Referring to my proposal for adding setnthcdr, and the number of
places where a list is currently truncated in the lisp files,

Richard Stallman <address@hidden> writes:

> I did not realize there were so many places where this was done.
> However, (setcdr (or (nthcdr N LIST) (list nil)) nil) is pretty
> simple.  I am not sure we need a new function to replace that
> even if that is done 20 times in Emacs.

Since the only practical use of the "setnthcdr" function is to simply
truncate a list to a specific length, I suggest a new function
truncate-list (to be defined in subr.el):

(defun truncate-list (list n)
  "Truncate list LIST to have a maximum of N elements.
If LIST has less than N element, do nothing."
   (if (setq list (nthcdr (1- n) list))
       (setcdr list nil)))

Using that function is both clearer and more efficient than
how it's done currently.

e.g. instead of

    (setq kill-ring (cons string kill-ring))
    (if (> (length kill-ring) kill-ring-max)
        (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)))

just write

    (truncate-list (setq kill-ring (cons string kill-ring))
                   kill-ring-max)


Also, it is much simpler to document truncate-list than the more
generic setnthcdr.

--
Kim F. Storm <address@hidden> http://www.cua.dk





reply via email to

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