Skip to content

Commit bfa6351

Browse files
committed
perf sort: Introduce addr_map_symbol__srcline() to make code more compact
Since we have 'struct addr_map_symbol' and the srcline sort order keys all operate on those, make the code more compact by introducing a function that receives a pointer to such struct and expands the arguments to map__srcline(). Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: https://lkml.kernel.org/n/tip-j540wq7n3ukkh70gk5be0in5@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent e2d88aa commit bfa6351

1 file changed

Lines changed: 17 additions & 20 deletions

File tree

‎tools/perf/util/sort.c‎

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -365,19 +365,20 @@ struct sort_entry sort_srcline = {
365365

366366
/* --sort srcline_from */
367367

368+
static char *addr_map_symbol__srcline(struct addr_map_symbol *ams)
369+
{
370+
return map__srcline(ams->map, ams->al_addr, ams->sym);
371+
}
372+
368373
static int64_t
369374
sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right)
370375
{
371-
if (!left->branch_info->srcline_from) {
372-
left->branch_info->srcline_from = map__srcline(left->branch_info->from.map,
373-
left->branch_info->from.al_addr,
374-
left->branch_info->from.sym);
375-
}
376-
if (!right->branch_info->srcline_from) {
377-
right->branch_info->srcline_from = map__srcline(right->branch_info->from.map,
378-
right->branch_info->from.al_addr,
379-
right->branch_info->from.sym);
380-
}
376+
if (!left->branch_info->srcline_from)
377+
left->branch_info->srcline_from = addr_map_symbol__srcline(&left->branch_info->from);
378+
379+
if (!right->branch_info->srcline_from)
380+
right->branch_info->srcline_from = addr_map_symbol__srcline(&right->branch_info->from);
381+
381382
return strcmp(right->branch_info->srcline_from, left->branch_info->srcline_from);
382383
}
383384

@@ -399,16 +400,12 @@ struct sort_entry sort_srcline_from = {
399400
static int64_t
400401
sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right)
401402
{
402-
if (!left->branch_info->srcline_to) {
403-
left->branch_info->srcline_to = map__srcline(left->branch_info->to.map,
404-
left->branch_info->to.al_addr,
405-
left->branch_info->to.sym);
406-
}
407-
if (!right->branch_info->srcline_to) {
408-
right->branch_info->srcline_to = map__srcline(right->branch_info->to.map,
409-
right->branch_info->to.al_addr,
410-
right->branch_info->to.sym);
411-
}
403+
if (!left->branch_info->srcline_to)
404+
left->branch_info->srcline_to = addr_map_symbol__srcline(&left->branch_info->to);
405+
406+
if (!right->branch_info->srcline_to)
407+
right->branch_info->srcline_to = addr_map_symbol__srcline(&right->branch_info->to);
408+
412409
return strcmp(right->branch_info->srcline_to, left->branch_info->srcline_to);
413410
}
414411

0 commit comments

Comments
 (0)