Testing for sameness first makes the logic simpler to follow. Signed-off-by: Jarno Rajahalme <jrajaha...@nicira.com> --- lib/rstp-state-machines.c | 57 +++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 33 deletions(-)
diff --git a/lib/rstp-state-machines.c b/lib/rstp-state-machines.c index e8b8438..5ae7124 100644 --- a/lib/rstp-state-machines.c +++ b/lib/rstp-state-machines.c @@ -2015,42 +2015,33 @@ compare_rstp_priority_vector(struct rstp_priority_vector *v1, RSTP_ID_ARGS(v2->root_bridge_id), v2->root_path_cost, RSTP_ID_ARGS(v2->designated_bridge_id), v2->designated_port_id); - if (v1->root_bridge_id < v2->root_bridge_id - || (v1->root_bridge_id == v2->root_bridge_id && - v1->root_path_cost < v2->root_path_cost) - || (v1->root_bridge_id == v2->root_bridge_id && - v1->root_path_cost == v2->root_path_cost && - v1->designated_bridge_id < v2->designated_bridge_id) - || (v1->root_bridge_id == v2->root_bridge_id && - v1->root_path_cost == v2->root_path_cost && - v1->designated_bridge_id == v2->designated_bridge_id && - v1->designated_port_id < v2->designated_port_id)) { - VLOG_DBG("superior_absolute"); - return SUPERIOR; - } else if ((v1->root_bridge_id > v2->root_bridge_id - || (v1->root_bridge_id == v2->root_bridge_id && - v1->root_path_cost > v2->root_path_cost) - || (v1->root_bridge_id == v2->root_bridge_id && - v1->root_path_cost == v2->root_path_cost && - v1->designated_bridge_id > v2->designated_bridge_id) - || (v1->root_bridge_id == v2->root_bridge_id && - v1->root_path_cost == v2->root_path_cost && - v1->designated_bridge_id == v2->designated_bridge_id && - v1->designated_port_id > v2->designated_port_id)) - && v1->designated_bridge_id == v2->designated_bridge_id - && v1->designated_port_id == v2->designated_port_id) { - VLOG_DBG("superior_same_des"); - return SUPERIOR; - } else if (v1->root_bridge_id == v2->root_bridge_id && - v1->root_path_cost == v2->root_path_cost && - v1->designated_bridge_id == v2->designated_bridge_id && - v1->designated_port_id == v2->designated_port_id) { + /* Testing for SAME first, so the SUPERIOR test can follow the logic above + * as is. */ + if (v1->root_bridge_id == v2->root_bridge_id + && v1->root_path_cost == v2->root_path_cost + && v1->designated_bridge_id == v2->designated_bridge_id + && v1->designated_port_id == v2->designated_port_id) { VLOG_DBG("same"); return SAME; - } else { - VLOG_DBG("inferior"); - return INFERIOR; } + if (v1->root_bridge_id < v2->root_bridge_id + || (v1->root_bridge_id == v2->root_bridge_id + && v1->root_path_cost < v2->root_path_cost) + || (v1->root_bridge_id == v2->root_bridge_id + && v1->root_path_cost == v2->root_path_cost + && v1->designated_bridge_id < v2->designated_bridge_id) + || (v1->root_bridge_id == v2->root_bridge_id + && v1->root_path_cost == v2->root_path_cost + && v1->designated_bridge_id == v2->designated_bridge_id + && v1->designated_port_id < v2->designated_port_id) + || (v1->designated_bridge_id == v2->designated_bridge_id + && v1->designated_port_id == v2->designated_port_id)) { + VLOG_DBG("superior"); + return SUPERIOR; + } + + VLOG_DBG("inferior"); + return INFERIOR; } static bool -- 1.7.10.4 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev