[PATCH 2/5] readelf: Pull same_set() info file scope
tbaeder@redhat.com
tbaeder@redhat.com
Fri Jan 8 08:16:30 GMT 2021
From: Timm Bäder <tbaeder@redhat.com>
Get rid of a nested function this way
Signed-off-by: Timm Bäder <tbaeder@redhat.com>
---
src/readelf.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/src/readelf.c b/src/readelf.c
index a95fc0aa..0157f8a2 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -12072,6 +12072,18 @@ compare_register_sets (const void *a, const void *b)
return compare_sets_by_info (*p1, *p2);
}
+static inline bool
+same_set (const struct register_info *a,
+ const struct register_info *b,
+ const struct register_info *regs,
+ size_t maxnreg)
+{
+ return (a < ®s[maxnreg] && a->regloc != NULL
+ && b < ®s[maxnreg] && b->regloc != NULL
+ && a->bits == b->bits
+ && (a->set == b->set || !strcmp (a->set, b->set)));
+}
+
static unsigned int
handle_core_registers (Ebl *ebl, Elf *core, const void *desc,
const Ebl_Register_Location *reglocs, size_t nregloc)
@@ -12110,19 +12122,11 @@ handle_core_registers (Ebl *ebl, Elf *core, const void *desc,
qsort (regs, maxreg + 1, sizeof regs[0], &compare_registers);
/* Collect the unique sets and sort them. */
- inline bool same_set (const struct register_info *a,
- const struct register_info *b)
- {
- return (a < ®s[maxnreg] && a->regloc != NULL
- && b < ®s[maxnreg] && b->regloc != NULL
- && a->bits == b->bits
- && (a->set == b->set || !strcmp (a->set, b->set)));
- }
struct register_info *sets[maxreg + 1];
sets[0] = ®s[0];
size_t nsets = 1;
for (int i = 1; i <= maxreg; ++i)
- if (regs[i].regloc != NULL && !same_set (®s[i], ®s[i - 1]))
+ if (regs[i].regloc != NULL && !same_set (®s[i], ®s[i - 1], regs, maxnreg))
sets[nsets++] = ®s[i];
qsort (sets, nsets, sizeof sets[0], &compare_register_sets);
@@ -12133,7 +12137,7 @@ handle_core_registers (Ebl *ebl, Elf *core, const void *desc,
/* Find the longest name of a register in this set. */
size_t maxname = 0;
const struct register_info *end;
- for (end = sets[i]; same_set (sets[i], end); ++end)
+ for (end = sets[i]; same_set (sets[i], end, regs, maxnreg); ++end)
{
size_t len = strlen (end->name);
if (len > maxname)
--
2.26.2
More information about the Elfutils-devel
mailing list