From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Dmitry Antipov <dmantipov@yandex.ru>
Cc: Emacs development discussions <emacs-devel@gnu.org>
Subject: Re: [PATCH] shrink struct vectorlike_header
Date: Thu, 11 Oct 2012 08:57:09 -0400 [thread overview]
Message-ID: <jwvsj9lkx1v.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <50766A2C.8070705@yandex.ru> (Dmitry Antipov's message of "Thu, 11 Oct 2012 10:41:48 +0400")
> This is an attempt to shrink struct vectorlike_header to the only
> 'size' field. For pseudovectors, 'size' field is rearranged to have
> one more bitfield to record the size of non-Lisp_Object area, thus
> giving the possibility to calculate the memory footprint of any
> vectorlike object.
Thanks, this is a very welcomed change (which will have to wait for the
freeze to end, of course).
> +/* When V is on the free list, V->contents[0] is used as a pointer to
> + next vector on the free list. */
> +
> +#define NEXT_IN_FREE_LIST(v) \
> + (*(struct Lisp_Vector **)((char *) v + header_size))
Please make the code match the comment, e.g:
(*(struct Lisp_Vector **)&(v->contents[0]))
> +/* For the large vector V, previous word is used as a pointer
> + to next large vector. */
> +
> +#define NEXT_LARGE_VECTOR(v) \
> + (*(struct Lisp_Vector **)((char *) v - sizeof (void *)))
You could also use the simpler:
(((struct Lisp_Vector **)v)[-1])
> +/* Convert from memory block used for large vector to the vector itself. */
> +
> +#define LARGE_VECTOR_START(mem) \
> + (struct Lisp_Vector *)((char *) mem + sizeof (void *))
> +
> +/* Convert from large vector to it's memory block. */
> +
> +#define LARGE_VECTOR_MEM(v) (void *)((char *) v - sizeof (void *))
Why not define a struct large_vector, so that NEXT_LARGE_VECTOR
can be (VECTOR_TO_LARGE (v)->next), LARGE_VECTOR_START (renamed to
LARGE_TO_VECTOR) can be (&(mem->vector)), and LARGE_VECTOR_MEM (renamed
to VECTOR_TO_LARGE) is defined maybe in terms of offsetof(vector)?
> +static ptrdiff_t
> +vector_nbytes (struct Lisp_Vector *v)
> +{
> + ptrdiff_t size = v->header.size & ~ARRAY_MARK_FLAG;
> +
> + if (size & PSEUDOVECTOR_FLAG)
> + {
> + if (PSEUDOVECTOR_TYPEP (&v->header, PVEC_BOOL_VECTOR))
> + return (bool_header_size
> + + (((struct Lisp_Bool_Vector *) v)->size
> + + BOOL_VECTOR_BITS_PER_CHAR - 1)
> + / BOOL_VECTOR_BITS_PER_CHAR);
> + return (header_size
> + + ((size & PSEUDOVECTOR_SIZE_MASK)
> + + ((size & PSEUDOVECTOR_REST_MASK)
> + >> PSEUDOVECTOR_SIZE_BITS)) * word_size);
> + }
> + return header_size + size * word_size;
I'd put an "else" before this last "return", so that if you forget a
"return" somewhere in the first branch of the "if", GCC will tell you.
> + PVEC_TYPE_MASK = 0x3f << PSEUDOVECTOR_AREA_BITS,
Please add a note where we define all the PVEC_foo types that the max
number of such types is limited by this 0x3f.
Stefan
next prev parent reply other threads:[~2012-10-11 12:57 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-11 6:41 [PATCH] shrink struct vectorlike_header Dmitry Antipov
2012-10-11 12:57 ` Stefan Monnier [this message]
2012-11-06 17:09 ` [RFC, PATCH] shrink struct vectorlike_header #2 Dmitry Antipov
2012-11-06 18:17 ` Stefan Monnier
2012-11-07 14:57 ` Dmitry Antipov
2012-11-08 3:08 ` Stefan Monnier
2012-11-08 5:25 ` Paul Eggert
2012-11-08 13:31 ` Dmitry Antipov
2012-11-08 14:03 ` Stefan Monnier
2012-11-08 14:45 ` Dmitry Antipov
2012-11-08 15:08 ` Dmitry Antipov
2012-11-08 16:30 ` Paul Eggert
2012-11-08 17:12 ` Andreas Schwab
2012-11-08 17:42 ` Nix
2012-11-09 18:04 ` Andreas Rottmann
2012-11-08 6:56 ` Stephen J. Turnbull
2012-11-06 20:53 ` Paul Eggert
2012-11-06 21:28 ` Eli Zaretskii
2012-10-11 16:42 ` [PATCH] shrink struct vectorlike_header Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvsj9lkx1v.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=dmantipov@yandex.ru \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).