[ofa-general] [PATCH] opensm: some micro-optimizations
Sasha Khapyorsky
sashak at voltaire.com
Sat Dec 22 05:33:50 PST 2007
- switch() instead of if/else if/else in osm_routing_engine_type_str()
- flow simplifications in osm_ucast_mgr_process()
Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
opensm/opensm/osm_opensm.c | 21 ++++++++++++---------
opensm/opensm/osm_ucast_mgr.c | 31 ++++++++++---------------------
2 files changed, 22 insertions(+), 30 deletions(-)
diff --git a/opensm/opensm/osm_opensm.c b/opensm/opensm/osm_opensm.c
index 7a73040..a78307c 100644
--- a/opensm/opensm/osm_opensm.c
+++ b/opensm/opensm/osm_opensm.c
@@ -90,22 +90,25 @@ const static struct routing_engine_module routing_modules[] = {
**********************************************************************/
const char *osm_routing_engine_type_str(IN osm_routing_engine_type_t type)
{
- if (type == OSM_ROUTING_ENGINE_TYPE_NONE)
+ switch (type) {
+ case OSM_ROUTING_ENGINE_TYPE_NONE:
return "none";
- else if (type == OSM_ROUTING_ENGINE_TYPE_MINHOP)
+ case OSM_ROUTING_ENGINE_TYPE_MINHOP:
return "minhop";
- else if (type == OSM_ROUTING_ENGINE_TYPE_UPDN)
+ case OSM_ROUTING_ENGINE_TYPE_UPDN:
return "updn";
- else if (type == OSM_ROUTING_ENGINE_TYPE_FILE)
+ case OSM_ROUTING_ENGINE_TYPE_FILE:
return "file";
- else if (type == OSM_ROUTING_ENGINE_TYPE_FTREE)
+ case OSM_ROUTING_ENGINE_TYPE_FTREE:
return "ftree";
- else if (type == OSM_ROUTING_ENGINE_TYPE_LASH)
+ case OSM_ROUTING_ENGINE_TYPE_LASH:
return "lash";
- else if (type == OSM_ROUTING_ENGINE_TYPE_DOR)
+ case OSM_ROUTING_ENGINE_TYPE_DOR:
return "dor";
- else
- return "unknown";
+ default:
+ break;
+ }
+ return "unknown";
}
/**********************************************************************
diff --git a/opensm/opensm/osm_ucast_mgr.c b/opensm/opensm/osm_ucast_mgr.c
index dd914e0..1841219 100644
--- a/opensm/opensm/osm_ucast_mgr.c
+++ b/opensm/opensm/osm_ucast_mgr.c
@@ -793,25 +793,17 @@ osm_signal_t osm_ucast_mgr_process(IN osm_ucast_mgr_t * const p_mgr)
p_mgr->any_change = FALSE;
- if (p_routing_eng->build_lid_matrices) {
- blm = p_routing_eng->build_lid_matrices(p_routing_eng->context);
- if (blm)
- osm_ucast_mgr_build_lid_matrices(p_mgr);
- } else
+ if (!p_routing_eng->build_lid_matrices ||
+ (blm = p_routing_eng->build_lid_matrices(p_routing_eng->context)))
osm_ucast_mgr_build_lid_matrices(p_mgr);
/*
Now that the lid matrices have been built, we can
build and download the switch forwarding tables.
*/
- if (p_routing_eng->ucast_build_fwd_tables) {
- ubft =
- p_routing_eng->ucast_build_fwd_tables(p_routing_eng->
- context);
- if (ubft)
- cl_qmap_apply_func(p_sw_guid_tbl,
- __osm_ucast_mgr_process_tbl, p_mgr);
- } else
+ if (!p_routing_eng->ucast_build_fwd_tables ||
+ (ubft =
+ p_routing_eng->ucast_build_fwd_tables(p_routing_eng->context)))
cl_qmap_apply_func(p_sw_guid_tbl, __osm_ucast_mgr_process_tbl,
p_mgr);
@@ -819,14 +811,11 @@ osm_signal_t osm_ucast_mgr_process(IN osm_ucast_mgr_t * const p_mgr)
if (p_routing_eng->name && (strcmp(p_routing_eng->name, "file") == 0)
&& (!blm || !ubft))
p_osm->routing_engine_used = OSM_ROUTING_ENGINE_TYPE_FILE;
- else {
- if (!blm && !ubft)
- p_osm->routing_engine_used =
- osm_routing_engine_type(p_routing_eng->name);
- else
- p_osm->routing_engine_used =
- OSM_ROUTING_ENGINE_TYPE_MINHOP;
- }
+ else if (!blm && !ubft)
+ p_osm->routing_engine_used =
+ osm_routing_engine_type(p_routing_eng->name);
+ else
+ p_osm->routing_engine_used = OSM_ROUTING_ENGINE_TYPE_MINHOP;
osm_log(p_mgr->p_log, OSM_LOG_INFO,
"osm_ucast_mgr_process: "
--
1.5.3.4.206.g58ba4
More information about the general
mailing list