elfcopy: Optimize for insertions at the end of the section list.

This is the common case when strip(1) is creating the output file.
The change provides a significant speedup when running on ELF files with
many sections.

PR:		234949
Reviewed by:	emaste
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D20444
This commit is contained in:
Mark Johnston 2019-05-30 15:28:48 +00:00
parent 5405b282e1
commit 0281687075
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=348431
2 changed files with 7 additions and 5 deletions

View File

@ -138,6 +138,8 @@ struct section {
TAILQ_ENTRY(section) sec_list; /* next section */
};
TAILQ_HEAD(sectionlist, section);
/* Internal data structure for segments. */
struct segment {
uint64_t vaddr; /* virtual addr (VMA) */

View File

@ -314,18 +314,18 @@ insert_to_sec_list(struct elfcopy *ecp, struct section *sec, int tail)
{
struct section *s;
if (!tail) {
if (tail || TAILQ_EMPTY(&ecp->v_sec) ||
TAILQ_LAST(&ecp->v_sec, sectionlist)->off <= sec->off) {
TAILQ_INSERT_TAIL(&ecp->v_sec, sec, sec_list);
} else {
TAILQ_FOREACH(s, &ecp->v_sec, sec_list) {
if (sec->off < s->off) {
TAILQ_INSERT_BEFORE(s, sec, sec_list);
goto inc_nos;
break;
}
}
}
TAILQ_INSERT_TAIL(&ecp->v_sec, sec, sec_list);
inc_nos:
if (sec->pseudo == 0)
ecp->nos++;
}