Re: [RFC][PATCH 09/16] objtool: Optimize find_symbol_*() and read_symbols()

Josh Poimboeuf
2020-03-15T16:41:50Z

On Thu, Mar 12, 2020 at 02:41:16PM +0100, Peter Zijlstra wrote:
> struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset)
> {
> - struct symbol *sym;
> + struct rb_node *node;
>
> - list_for_each_entry(sym, &sec->symbol_list, list)
> - if (sym->type != STT_SECTION &&
> - sym->offset == offset)
> - return sym;
> + rb_for_each(&sec->symbol_tree, node, &offset, symbol_by_offset) {
> + struct symbol *s = rb_entry(node, struct symbol, node);
> +
> + if (s->offset != offset)
> + continue;
> +
> + if (s->type != STT_SECTION)
> + return s;
> + }

Can be simplified to:

if (s->offset == offset && s->type != STT_SECTION)
return s;

--
Josh