mirror of https://github.com/dynup/kpatch
improve find_[symbol|section]_by_index
The indexes are in order when being read from the table. Just index directly into the table; a benefit of using an array for this structure instead of a linked list. Removes another hot path during the rela table initialization. Signed-off-by: Seth Jennings <sjenning@redhat.com>
This commit is contained in:
parent
24894d263c
commit
634b9cee78
|
@ -173,14 +173,9 @@ int is_rela_section(struct section *sec)
|
|||
|
||||
struct section *find_section_by_index(struct table *table, unsigned int index)
|
||||
{
|
||||
struct section *sec;
|
||||
int i;
|
||||
|
||||
for_each_section(i, sec, table)
|
||||
if (sec->index == index)
|
||||
return sec;
|
||||
|
||||
return NULL;
|
||||
if (index == 0 || index >= table->nr)
|
||||
return NULL;
|
||||
return &((struct section *)(table->data))[index-1];
|
||||
}
|
||||
|
||||
struct section *find_section_by_name(struct table *table, const char *name)
|
||||
|
@ -197,14 +192,9 @@ struct section *find_section_by_name(struct table *table, const char *name)
|
|||
|
||||
struct symbol *find_symbol_by_index(struct table *table, size_t index)
|
||||
{
|
||||
struct symbol *sym;
|
||||
int i;
|
||||
|
||||
for_each_symbol_zero(i, sym, table)
|
||||
if (sym->index == index)
|
||||
return sym;
|
||||
|
||||
return NULL;
|
||||
if (index >= table->nr)
|
||||
return NULL;
|
||||
return &((struct symbol *)(table->data))[index];
|
||||
}
|
||||
|
||||
struct symbol *find_symbol_by_name(struct table *table, const char *name)
|
||||
|
|
Loading…
Reference in New Issue