summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatus Fabian <matfabia@cisco.com>2015-12-14 10:31:33 -0500
committerDamjan Marion <damarion@cisco.com>2015-12-15 00:09:46 +0100
commitd2dc3df90d20419dfaee03f3096ed18d20fa391a (patch)
tree3315705df01fdb840ddb828fff779748154930b8
parentf9bd620dc5299180cb639c4c6f91fadf6b860b08 (diff)
replacing all vec_sort() invocations to vec_sort_with_function()
Change-Id: I05895827ed52be292112484cee7d0a2591b67335 Signed-off-by: Matus Fabian <matfabia@cisco.com>
-rw-r--r--vlib/vlib/cli.c22
-rw-r--r--vlib/vlib/mc.c11
-rw-r--r--vlib/vlib/node_cli.c15
-rw-r--r--vlib/vlib/parse.c3
-rw-r--r--vlib/vlib/trace.c14
-rw-r--r--vnet/vnet/config.c11
-rw-r--r--vnet/vnet/ip/lookup.c27
-rw-r--r--vnet/vnet/mpls-gre/mpls.c34
-rw-r--r--vpp-api-test/vat/api_format.c32
-rw-r--r--vpp-japi/japi/vppjni.c12
-rw-r--r--vpp/api/api.c11
-rw-r--r--vppinfra/vppinfra/elog.c12
-rw-r--r--vppinfra/vppinfra/test_timing_wheel.c22
13 files changed, 186 insertions, 40 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++)
{
diff --git a/vnet/vnet/config.c b/vnet/vnet/config.c
index 74c4caa847f..9f98778fb28 100644
--- a/vnet/vnet/config.c
+++ b/vnet/vnet/config.c
@@ -217,6 +217,15 @@ remove_reference (vnet_config_main_t * cm, vnet_config_t * c)
}
}
+static int
+feature_cmp (void * a1, void * a2)
+{
+ vnet_config_feature_t * f1 = a1;
+ vnet_config_feature_t * f2 = a2;
+
+ return (int) f1->feature_index - f2->feature_index;
+}
+
always_inline u32 *
vnet_get_config_heap (vnet_config_main_t * cm, u32 ci)
{ return heap_elt_at_index (cm->config_string_heap, ci); }
@@ -259,7 +268,7 @@ u32 vnet_config_add_feature (vlib_main_t * vm,
/* Sort (prioritize) features. */
if (vec_len (new_features) > 1)
- vec_sort (new_features, f1, f2, (int) f1->feature_index - f2->feature_index);
+ vec_sort_with_function (new_features, feature_cmp);
if (old)
remove_reference (cm, old);
diff --git a/vnet/vnet/ip/lookup.c b/vnet/vnet/ip/lookup.c
index 80f0a33e731..9c125c2e9c2 100644
--- a/vnet/vnet/ip/lookup.c
+++ b/vnet/vnet/ip/lookup.c
@@ -1814,6 +1814,16 @@ typedef CLIB_PACKED (struct {
u32 index : 26;
}) ip4_route_t;
+static int
+ip4_route_cmp (void * a1, void * a2)
+{
+ ip4_route_t * r1 = a1;
+ ip4_route_t * r2 = a2;
+
+ int cmp = ip4_address_compare (&r1->address, &r2->address);
+ return cmp ? cmp : ((int) r1->address_length - (int) r2->address_length);
+}
+
static clib_error_t *
ip4_show_fib (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
{
@@ -1949,9 +1959,7 @@ ip4_show_fib (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * c
}
}
- vec_sort (routes, r1, r2,
- ({ int cmp = ip4_address_compare (&r1->address, &r2->address);
- cmp ? cmp : ((int) r1->address_length - (int) r2->address_length); }));
+ vec_sort_with_function (routes, ip4_route_cmp);
if (vec_len(routes)) {
if (include_empty_fibs == 0)
vlib_cli_output (vm, "Table %d, fib_index %d, flow hash: %U",
@@ -2104,6 +2112,15 @@ static void count_routes_in_fib_at_prefix_length
ap->count_by_prefix_length[mask_width]++;
}
+static int
+ip6_route_cmp (void * a1, void * a2)
+{
+ ip6_route_t * r1 = a1;
+ ip6_route_t * r2 = a2;
+
+ int cmp = ip6_address_compare (&r1->address, &r2->address);
+ return cmp ? cmp : ((int) r1->address_length - (int) r2->address_length);
+}
static clib_error_t *
ip6_show_fib (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
@@ -2172,9 +2189,7 @@ ip6_show_fib (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * c
BV(clib_bihash_foreach_key_value_pair)(h, add_routes_in_fib, a);
- vec_sort (routes, r1, r2,
- ({ int cmp = ip6_address_compare (&r1->address, &r2->address);
- cmp ? cmp : ((int) r1->address_length - (int) r2->address_length); }));
+ vec_sort_with_function (routes, ip6_route_cmp);
vlib_cli_output (vm, "%=45s%=16s%=16s%=16s",
"Destination", "Packets", "Bytes", "Adjacency");
diff --git a/vnet/vnet/mpls-gre/mpls.c b/vnet/vnet/mpls-gre/mpls.c
index 431a69b4ab0..1e1a0970ec3 100644
--- a/vnet/vnet/mpls-gre/mpls.c
+++ b/vnet/vnet/mpls-gre/mpls.c
@@ -585,6 +585,33 @@ typedef struct {
u32 label;
} show_mpls_fib_t;
+static int
+mpls_dest_cmp(void * a1, void * a2)
+{
+ show_mpls_fib_t * r1 = a1;
+ show_mpls_fib_t * r2 = a2;
+
+ return clib_net_to_host_u32(r1->dest) - clib_net_to_host_u32(r2->dest);
+}
+
+static int
+mpls_fib_index_cmp(void * a1, void * a2)
+{
+ show_mpls_fib_t * r1 = a1;
+ show_mpls_fib_t * r2 = a2;
+
+ return r1->fib_index - r2->fib_index;
+}
+
+static int
+mpls_label_cmp(void * a1, void * a2)
+{
+ show_mpls_fib_t * r1 = a1;
+ show_mpls_fib_t * r2 = a2;
+
+ return r1->label - r2->label;
+}
+
static clib_error_t *
show_mpls_fib_command_fn (vlib_main_t * vm,
unformat_input_t * input,
@@ -614,9 +641,8 @@ show_mpls_fib_command_fn (vlib_main_t * vm,
goto decap_table;
}
/* sort output by dst address within fib */
- vec_sort (records, r0, r1, clib_net_to_host_u32(r0->dest) -
- clib_net_to_host_u32(r1->dest));
- vec_sort (records, r0, r1, r0->fib_index - r1->fib_index);
+ vec_sort_with_function (records, mpls_dest_cmp);
+ vec_sort_with_function (records, mpls_fib_index_cmp);
vlib_cli_output (vm, "MPLS encap table");
vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
vec_foreach (s, records)
@@ -645,7 +671,7 @@ show_mpls_fib_command_fn (vlib_main_t * vm,
goto out;
}
- vec_sort (records, r0, r1, r0->label - r1->label);
+ vec_sort_with_function (records, mpls_label_cmp);
vlib_cli_output (vm, "MPLS decap table");
vlib_cli_output (vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
diff --git a/vpp-api-test/vat/api_format.c b/vpp-api-test/vat/api_format.c
index 02c3ad5fe06..352a78a6a4a 100644
--- a/vpp-api-test/vat/api_format.c
+++ b/vpp-api-test/vat/api_format.c
@@ -2019,6 +2019,14 @@ static int dump_sub_interface_table (vat_main_t * vam)
return 0;
}
+static int name_sort_cmp (void * a1, void * a2)
+{
+ name_sort_t * n1 = a1;
+ name_sort_t * n2 = a2;
+
+ return strcmp ((char *)n1->name, (char *)n2->name);
+}
+
static int dump_interface_table (vat_main_t * vam)
{
hash_pair_t * p;
@@ -2036,8 +2044,7 @@ static int dump_interface_table (vat_main_t * vam)
ns->value = (u32) p->value[0];
}));
- vec_sort (nses, n1, n2,
- strcmp ((char *)n1->name, (char *)n2->name));
+ vec_sort_with_function (nses, name_sort_cmp);
fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
vec_foreach (ns, nses) {
@@ -8275,6 +8282,14 @@ static int comment (vat_main_t * vam)
return 0;
}
+static int cmd_cmp (void * a1, void * a2)
+{
+ u8 ** c1 = a1;
+ u8 ** c2 = a2;
+
+ return strcmp ((char *)(c1[0]), (char *)(c2[0]));
+}
+
static int help (vat_main_t * vam)
{
u8 ** cmds = 0;
@@ -8304,8 +8319,7 @@ static int help (vat_main_t * vam)
vec_add1 (cmds, (u8 *)(p->key));
}));
- vec_sort (cmds, c1, c2,
- strcmp ((char *)(c1[0]), (char *)(c2[0])));
+ vec_sort_with_function (cmds, cmd_cmp);
for (j = 0; j < vec_len(cmds); j++)
fformat (vam->ofp, "%s\n", cmds[j]);
@@ -8356,6 +8370,14 @@ typedef struct {
} macro_sort_t;
+static int macro_sort_cmp (void * a1, void * a2)
+{
+ macro_sort_t * s1 = a1;
+ macro_sort_t * s2 = a2;
+
+ return strcmp ((char *)(s1->name), (char *)(s2->name));
+}
+
static int dump_macro_table (vat_main_t * vam)
{
macro_sort_t * sort_me = 0, * sm;
@@ -8369,7 +8391,7 @@ static int dump_macro_table (vat_main_t * vam)
sm->value = (u8 *) (p->value[0]);
}));
- vec_sort (sort_me, s1, s2, strcmp ((char *)(s1->name), (char *)(s2->name)));
+ vec_sort_with_function (sort_me, macro_sort_cmp);
if (vec_len(sort_me))
fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
diff --git a/vpp-japi/japi/vppjni.c b/vpp-japi/japi/vppjni.c
index 740a3425d90..4274c31dd91 100644
--- a/vpp-japi/japi/vppjni.c
+++ b/vpp-japi/japi/vppjni.c
@@ -362,6 +362,15 @@ out:
return (rv);
}
+static int
+name_sort_cmp (void * a1, void * a2)
+{
+ name_sort_t * n1 = a1;
+ name_sort_t * n2 = a2;
+
+ return strcmp ((char *)n1->name, (char *)n2->name);
+}
+
JNIEXPORT jstring JNICALL Java_org_openvpp_vppjapi_vppConn_getInterfaceList
(JNIEnv * env, jobject obj, jstring name_filter)
{
@@ -387,8 +396,7 @@ JNIEXPORT jstring JNICALL Java_org_openvpp_vppjapi_vppConn_getInterfaceList
}
}));
- vec_sort (nses, n1, n2,
- strcmp ((char *)n1->name, (char *)n2->name));
+ vec_sort_with_function (nses, name_sort_cmp);
vec_foreach (ns, nses)
s = format (s, "%s: %d, ", ns->name, ns->value);
diff --git a/vpp/api/api.c b/vpp/api/api.c
index a1e7f020e6c..7bbb5c030cd 100644
--- a/vpp/api/api.c
+++ b/vpp/api/api.c
@@ -388,6 +388,15 @@ int vl_api_memclnt_delete_callback (u32 client_index)
#define API_LINK_STATE_EVENT 1
#define API_ADMIN_UP_DOWN_EVENT 2
+static int
+event_data_cmp (void * a1, void * a2)
+{
+ uword * e1 = a1;
+ uword * e2 = a2;
+
+ return (word) e1[0] - (word) e2[0];
+}
+
static uword
link_state_process (vlib_main_t * vm,
vlib_node_runtime_t * rt,
@@ -414,7 +423,7 @@ link_state_process (vlib_main_t * vm,
(vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
/* Sort, so we can eliminate duplicates */
- vec_sort (event_data, e1, e2, (word) e1[0] - (word) e2[0]);
+ vec_sort_with_function (event_data, event_data_cmp);
prev_sw_if_index = ~0;
diff --git a/vppinfra/vppinfra/elog.c b/vppinfra/vppinfra/elog.c
index b0570afc002..3c327481141 100644
--- a/vppinfra/vppinfra/elog.c
+++ b/vppinfra/vppinfra/elog.c
@@ -562,6 +562,14 @@ static void maybe_fix_string_table_offset (elog_event_t * e,
}
}
+static int elog_cmp (void * a1, void * a2)
+{
+ elog_event_t * e1 = a1;
+ elog_event_t * e2 = a2;
+
+ return e1->time - e2->time;
+}
+
void elog_merge (elog_main_t * dst, u8 * dst_tag,
elog_main_t * src, u8 * src_tag)
{
@@ -668,7 +676,7 @@ void elog_merge (elog_main_t * dst, u8 * dst_tag,
}
/* Sort events by increasing time. */
- vec_sort (dst->events, e1, e2, e1->time < e2->time ? -1 : (e1->time > e2->time ? +1 : 0));
+ vec_sort_with_function (dst->events, elog_cmp);
/* Recreate the event ring or the results won't serialize */
{
@@ -960,7 +968,7 @@ serialize_elog_main (serialize_main_t * m, va_list * va)
serialize_integer (m, vec_len (em->events), sizeof (u32));
/* SMP logs can easily have local time paradoxes... */
- vec_sort (em->events, e0, e1, e0->time - e1->time);
+ vec_sort_with_function (em->events, elog_cmp);
vec_foreach (e, em->events)
serialize (m, serialize_elog_event, em, e);
diff --git a/vppinfra/vppinfra/test_timing_wheel.c b/vppinfra/vppinfra/test_timing_wheel.c
index fa3113205c5..81483027905 100644
--- a/vppinfra/vppinfra/test_timing_wheel.c
+++ b/vppinfra/vppinfra/test_timing_wheel.c
@@ -54,6 +54,12 @@ typedef struct {
f64 time_next_status_update;
} test_timing_wheel_main_t;
+typedef struct {
+ f64 dt;
+ f64 fraction;
+ u64 count;
+} test_timing_wheel_tmp_t;
+
static void set_event (test_timing_wheel_main_t * tm, uword i)
{
timing_wheel_t * w = &tm->timing_wheel;
@@ -70,6 +76,14 @@ static void set_event (test_timing_wheel_main_t * tm, uword i)
tm->events[i] = cpu_time;
}
+static int test_timing_wheel_tmp_cmp (void * a1, void * a2)
+{
+ test_timing_wheel_tmp_t * f1 = a1;
+ test_timing_wheel_tmp_t * f2 = a2;
+
+ return f1->dt < f2->dt ? -1 : (f1->dt > f2->dt ? +1 : 0);
+}
+
clib_error_t *
test_timing_wheel_main (unformat_input_t * input)
{
@@ -294,11 +308,7 @@ test_timing_wheel_main (unformat_input_t * input)
min_error, max_error);
{
- struct tmp {
- f64 dt;
- f64 fraction;
- u64 count;
- } * fs, * f;
+ test_timing_wheel_tmp_t * fs, * f;
f64 total_fraction;
fs = 0;
@@ -313,7 +323,7 @@ test_timing_wheel_main (unformat_input_t * input)
f->count = error_hist[i];
}
- vec_sort (fs, f1, f2, f1->dt < f2->dt ? -1 : (f1->dt > f2->dt ? +1 : 0));
+ vec_sort_with_function (fs, test_timing_wheel_tmp_cmp);
total_fraction = 0;
vec_foreach (f, fs)