emacs-devel
[Top][All Lists]
Advanced

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

Re: JSON->lisp Mapping: Hash vs AList


From: Clément Pit-Claudel
Subject: Re: JSON->lisp Mapping: Hash vs AList
Date: Mon, 18 Dec 2017 11:15:14 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0

On 2017-12-17 12:44, Philipp Stephani wrote:
>     >  > +              result = Fnreverse (result);
>     >
>     >  Is there a reason for calling nreverse here?
>     >
>     > It puts the elements in the same order as the original JSON. (The 
> Jansson parser also retains the original
>     > order.)
>     > This isn't very important, just a bit nicer and less surprising.
> 
>     It's a potential performance hit, but if you think it's worthwhile,
>     it's fine with me.
> 
> I don't care much. For now I'd leave it in, we can take it out later if it 
> hurts performance too much. (Though people that care about performance should 
> probably use hashtables anyway.)

Would it make it faster to construct the list in order, instead of constructing 
it in reverse and then reversing it?

Something like the following, but in C:

;; the direct version
(defun map-fn-over-list (fn list)
  (when list
    (let* ((out (cons (funcall fn (pop list)) nil))
           (lastcdr out))
      (while list
        (setcdr lastcdr (cons (funcall fn (pop list)) nil))
        (setq lastcdr (cdr lastcdr)))
      out)))
 Clément.



reply via email to

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