emacs-devel
[Top][All Lists]
Advanced

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

Re: feature/native-comp ec88bdb 1/4: * Add a simple growable vector like


From: Pip Cet
Subject: Re: feature/native-comp ec88bdb 1/4: * Add a simple growable vector like type
Date: Wed, 24 Feb 2021 04:46:40 +0000

On Tue, Feb 23, 2021 at 11:25 PM Andrea Corallo <akrl@savannah.gnu.org> wrote:
> +(defsubst comp-vec-length (vec)
> +  "Return the number of elements of VEC."
> +  (+ (comp-vec-beg vec) (comp-vec-end vec)))

Should this be (- (comp-vec-end vec) (comp-vec-beg vec))?

> +(defsubst comp-vec-append (vec elt)
> +  "Append ELT into VEC.
> +ELT is returned."
> +  (puthash (comp-vec-end vec) elt (comp-vec-aref vec))
> +  (cl-incf (comp-vec-end vec))
> +  elt)

I'd prefer, for aesthetic reasons, to have the incf first (increasing
the size of the vector), then puthashing elt at (1- (comp-vec-end
vec)).

Also, shouldn't the (comp-vec-aref vec) be a (comp-vec-data vec)?

(puthash (1- (incf (comp-vec-end vec))) elt (comp-vec-data vec))

> +(defsubst comp-vec-prepend (vec elt)
> +  "Prepend ELT into VEC.
> +ELT is returned."
> +  (puthash (comp-vec-beg vec) elt (comp-vec-aref vec))
> +  (cl-decf (comp-vec-beg vec))
> +  elt)

Does this need to decf first, then puthash?

(puthash (decf (comp-vec-beg vec)) elt (comp-vec-data vec)))



reply via email to

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