From 0471a2d6c95dd93a4969fdccbde3e4abfa27f933 Mon Sep 17 00:00:00 2001 From: Jianpeng Ma Date: Fri, 8 Jan 2021 16:11:27 +0800 Subject: [PATCH] msg: using switch-case in place of if-else. For point of performance, swith-case is better than if-else for blackhole check. Signed-off-by: Jianpeng Ma --- src/msg/Connection.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/msg/Connection.cc b/src/msg/Connection.cc index 21f147b803496..9183871b59429 100644 --- a/src/msg/Connection.cc +++ b/src/msg/Connection.cc @@ -7,8 +7,17 @@ bool Connection::is_blackhole() const { auto& conf = msgr->cct->_conf; - return ((conf->ms_blackhole_mon && peer_type == CEPH_ENTITY_TYPE_MON) || - (conf->ms_blackhole_osd && peer_type == CEPH_ENTITY_TYPE_OSD) || - (conf->ms_blackhole_mds && peer_type == CEPH_ENTITY_TYPE_MDS) || - (conf->ms_blackhole_client && peer_type == CEPH_ENTITY_TYPE_CLIENT)); + + switch (peer_type) { + case CEPH_ENTITY_TYPE_MON: + return conf->ms_blackhole_mon; + case CEPH_ENTITY_TYPE_OSD: + return conf->ms_blackhole_osd; + case CEPH_ENTITY_TYPE_MDS: + return conf->ms_blackhole_mds; + case CEPH_ENTITY_TYPE_CLIENT: + return conf->ms_blackhole_client; + default: + return false; + } } -- 2.39.5