diff options
Diffstat (limited to 'vlib')
-rw-r--r-- | vlib/vlib/cli.c | 22 | ||||
-rw-r--r-- | vlib/vlib/mc.c | 11 | ||||
-rw-r--r-- | vlib/vlib/node_cli.c | 15 | ||||
-rw-r--r-- | vlib/vlib/parse.c | 3 | ||||
-rw-r--r-- | vlib/vlib/trace.c | 14 |
5 files changed, 52 insertions, 13 deletions
diff --git a/vlib/vlib/cli.c b/vlib/vlib/cli.c index e5163f260e1..e0e54fd4f65 100644 --- a/vlib/vlib/cli.c +++ b/vlib/vlib/cli.c @@ -296,6 +296,24 @@ all_subs (vlib_cli_main_t * cm, return subs; } +static int +vlib_cli_cmp_rule (void * a1, void * a2) +{ + vlib_cli_sub_rule_t * r1 = a1; + vlib_cli_sub_rule_t * r2 = a2; + + return vec_cmp (r1->name, r2->name); +} + +static int +vlib_cli_cmp_command (void * a1, void * a2) +{ + vlib_cli_command_t * c1 = a1; + vlib_cli_command_t * c2 = a2; + + return vec_cmp (c1->path, c2->path); +} + static clib_error_t * vlib_cli_dispatch_sub_commands (vlib_main_t * vm, vlib_cli_main_t * cm, @@ -351,7 +369,7 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm, sr->rule_index = ~0; } - vec_sort (subs, c1, c2, vec_cmp (c1->name, c2->name)); + vec_sort_with_function (subs, vlib_cli_cmp_rule); for (i = 0; i < vec_len (subs); i++) { @@ -382,7 +400,7 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm, vlib_cli_command_t * sub, * subs; subs = all_subs (cm, 0, parent_command_index); - vec_sort (subs, c1, c2, vec_cmp (c1->path, c2->path)); + vec_sort_with_function (subs, vlib_cli_cmp_command); vec_foreach (sub, subs) vlib_cli_output (vm, " %-40U %U", format_vlib_cli_path, sub->path, diff --git a/vlib/vlib/mc.c b/vlib/vlib/mc.c index 460145ef0e6..d311e8e0889 100644 --- a/vlib/vlib/mc.c +++ b/vlib/vlib/mc.c @@ -2273,6 +2273,15 @@ static u8 * format_mc_stream_state (u8 * s, va_list * args) return format (s, "%s", t); } +static int +mc_peer_comp (void * a1, void * a2) +{ + mc_stream_peer_t * p1 = a1; + mc_stream_peer_t * p2 = a2; + + return mc_peer_id_compare (p1->id, p2->id); +} + u8 * format_mc_main (u8 * s, va_list * args) { mc_main_t * mcm = va_arg (*args, mc_main_t *); @@ -2331,7 +2340,7 @@ u8 * format_mc_main (u8 * s, va_list * args) if (clib_bitmap_get (t->all_peer_bitmap, p - t->peers)) vec_add1 (ps, p[0]); })); - vec_sort (ps, p1, p2, mc_peer_id_compare (p1->id, p2->id)); + vec_sort_with_function (ps, mc_peer_comp); s = format (s, "\n%U%=30s%10s%16s%16s", format_white_space, indent + 6, "Peer", "Last seq", "Retries", "Future"); diff --git a/vlib/vlib/node_cli.c b/vlib/vlib/node_cli.c index 58c3776a67b..59f5623eca4 100644 --- a/vlib/vlib/node_cli.c +++ b/vlib/vlib/node_cli.c @@ -40,6 +40,15 @@ #include <vlib/vlib.h> #include <vlib/threads.h> +static int +node_cmp (void * a1, void *a2) +{ + vlib_node_t ** n1 = a1; + vlib_node_t ** n2 = a2; + + return vec_cmp (n1[0]->name, n2[0]->name); +} + static clib_error_t * show_node_graph (vlib_main_t * vm, unformat_input_t * input, @@ -61,8 +70,7 @@ show_node_graph (vlib_main_t * vm, vlib_node_t ** nodes = vec_dup (nm->nodes); uword i; - vec_sort (nodes, n1, n2, - vec_cmp (n1[0]->name, n2[0]->name)); + vec_sort_with_function (nodes, node_cmp); for (i = 0; i < vec_len (nodes); i++) vlib_cli_output (vm, "%U\n\n", format_vlib_node_graph, nm, nodes[i]); @@ -282,8 +290,7 @@ show_node_runtime (vlib_main_t * vm, stat_vm = stat_vms[j]; nodes = node_dups[j]; - vec_sort (nodes, n1, n2, - vec_cmp (n1[0]->name, n2[0]->name)); + vec_sort_with_function (nodes, node_cmp); n_input = n_output = n_drop = n_punt = n_clocks = 0; n_internal_vectors = n_internal_calls = 0; diff --git a/vlib/vlib/parse.c b/vlib/vlib/parse.c index 844be8aafe3..cea8f7515a0 100644 --- a/vlib/vlib/parse.c +++ b/vlib/vlib/parse.c @@ -965,8 +965,7 @@ static clib_error_t * parse_init (vlib_main_t *vm) } vec_free (bounds); - vec_sort (pm->parse_registrations, r1, r2, - rule_length_compare (r1[0], r2[0])); + vec_sort_with_function (pm->parse_registrations, rule_length_compare); for (i = 0; i < vec_len (pm->parse_registrations); i++) { diff --git a/vlib/vlib/trace.c b/vlib/vlib/trace.c index 6272d853145..43c000f4ccf 100644 --- a/vlib/vlib/trace.c +++ b/vlib/vlib/trace.c @@ -170,6 +170,15 @@ VLIB_CLI_COMMAND (trace_cli_command,static) = { .short_help = "Packet tracer commands", }; +static int +trace_cmp (void * a1, void * a2) +{ + vlib_trace_header_t ** t1 = a1; + vlib_trace_header_t ** t2 = a2; + i64 dt = t1[0]->time - t2[0]->time; + return dt < 0 ? -1 : (dt > 0 ? +1 : 0); +} + static clib_error_t * cli_show_trace_buffer (vlib_main_t * vm, unformat_input_t * input, @@ -206,10 +215,7 @@ cli_show_trace_buffer (vlib_main_t * vm, } /* Sort them by increasing time. */ - vec_sort (traces, t0, t1, ({ - i64 dt = t0[0]->time - t1[0]->time; - dt < 0 ? -1 : (dt > 0 ? +1 : 0); - })); + vec_sort_with_function (traces, trace_cmp); for (i = 0; i < vec_len (traces); i++) { |