From 69c5f2c6a54e41382ffb37f4fd8f8aca54020ec2 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Thu, 6 Jun 2019 03:03:54 +0000 Subject: [PATCH] MFC r348431: elfcopy: Optimize for insertions at the end of the section list. PR: 234949 --- contrib/elftoolchain/elfcopy/elfcopy.h | 2 ++ contrib/elftoolchain/elfcopy/sections.c | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/contrib/elftoolchain/elfcopy/elfcopy.h b/contrib/elftoolchain/elfcopy/elfcopy.h index a6578113fe5..85a9a9a1224 100644 --- a/contrib/elftoolchain/elfcopy/elfcopy.h +++ b/contrib/elftoolchain/elfcopy/elfcopy.h @@ -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) */ diff --git a/contrib/elftoolchain/elfcopy/sections.c b/contrib/elftoolchain/elfcopy/sections.c index f8134f94461..624c21ba238 100644 --- a/contrib/elftoolchain/elfcopy/sections.c +++ b/contrib/elftoolchain/elfcopy/sections.c @@ -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++; } -- 2.45.0