From: Nick Clifton <nickc@redhat.com>
To: "Martin Storsjö" <martin@martin.st>, binutils@sourceware.org
Subject: Re: [PATCH] ld: pe: Improve performance of object file exclude symbol directives
Date: Mon, 5 Sep 2022 13:54:11 +0100 [thread overview]
Message-ID: <174963e9-fa71-b70e-7659-0f534db073f8@redhat.com> (raw)
In-Reply-To: <20220902105903.2249507-1-martin@martin.st>
Hi Martin,
> Store the list of excluded symbols in a sorted list, speeding up
> checking for duplicates when inserting new entries.
An excellent idea.
> /* From EXCLUDE_SYMBOLS or embedded directives. */
> + int num_exclude_symbols;
Presumably there can never be a negative number of excluded symbols,
so using "unsigned int" here might be more appropriate.
> + if (fdef->exclude_symbols)
Given that the for() loop to follow checks fdef->num_exclude_symbols,
this if() statement is redundant.
> + for (i = 0; i < fdef->num_exclude_symbols; i++)
> + free (fdef->exclude_symbols[i].symbol_name);
> + free (fdef->exclude_symbols);
Calling free(NULL) is allowed, so the if() statement is still not needed.
> +/* Search the position of the identical element, or returns the position
> + of the next higher element. If last valid element is smaller, then MAX
> + is returned. */
The comment should explain the use of the IS_IDENT parameter.
It should probably also note that MAX is expected to be the same as the number
of entries in the B array.
> +static int
> +find_exclude_in_list (def_file_exclude_symbol *b, int max,
> + const char *name, int *is_ident)
Since we are dealing with array indicies here, I would suggest that the function
should return an unsigned int. Likewise the MAX parameter should be unsigned.
Plus is_ident should be a boolean pointer, not an integer pointer.
> +static def_file_exclude_symbol *
> +def_file_add_exclude_symbol (def_file *fdef, const char *name, int *is_dup)
I think that IS_DUP should be a "boolean *" not a "int *".
> + int max_exclude_symbols = ROUND_UP(fdef->num_exclude_symbols, 32);
Magic numbers are bad. Please replace 32 with a defined constant.
> + if (fdef->num_exclude_symbols >= max_exclude_symbols)
This is sneaky and not very intuitive. I would prefer it if you had
two fields in the fdef structure, one for the number of allocated
slots in the exclude_symbols array and one for the number of used slots.
Then testing for when the array needs to be extended would be a case
of comparing these two fields. Using two fields might take up more
space in the structure, but it sure makes a lot more sense to me.
> + max_exclude_symbols = ROUND_UP(fdef->num_exclude_symbols + 1, 32);
Given that the point of this patch is to improve performance when there
are a large number of excluded symbols, incrementing the array by 32 slots
at a time seems counter intuitive. I would suggest a bigger number, eg 1024
or 10240.
> + e = fdef->exclude_symbols + pos;
> + if (pos != fdef->num_exclude_symbols)
> + memmove (&e[1], e, (sizeof (def_file_exclude_symbol) * (fdef->num_exclude_symbols - pos)));
What the ? OK, so what is going on here ? At the very least I think that
you are going to need to add a comment to this piece of code.
Cheers
Nick
Cheers
Nick
next prev parent reply other threads:[~2022-09-05 12:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-02 10:59 Martin Storsjö
2022-09-05 12:54 ` Nick Clifton [this message]
2022-09-06 7:40 ` Jan Beulich
2022-09-06 11:42 ` Nick Clifton
2022-09-06 11:54 ` Jan Beulich
2022-09-06 11:59 ` Martin Storsjö
2022-09-06 13:06 ` Nick Clifton
2022-09-06 9:39 ` Martin Storsjö
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=174963e9-fa71-b70e-7659-0f534db073f8@redhat.com \
--to=nickc@redhat.com \
--cc=binutils@sourceware.org \
--cc=martin@martin.st \
/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.
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).