Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1298543

[PATCHv2] staging: most: replace multiple if..else with table lookup

Path csiph.com!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod
From "Gujulan Elango, Hari Prasath (H.)" <hgujulan@visteon.com>
Newsgroups linux.kernel
Subject [PATCHv2] staging: most: replace multiple if..else with table lookup
Date Mon, 28 Dec 2015 10:00:01 +0100
Message-ID <qKBON-7Wd-1@gated-at.bofh.it> (permalink)
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=visteon.onmicrosoft.com; s=selector1-visteon-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=DqJkWx05dtTGcMGHKv/Kts3Yts3l90ns7ww4ovkfpFo=; b=b066jA0BNoUBpkB+rYS+rjPquitWLTkFAUlmDEx94jJ9Jn7moyOWWezVzFhcImAdB2bbegi3oOvjarPXiNGCNS8ZjzMmlGEi1IJMXNsHo+cKr3PreF5jec6NhbmDDs8Vj6XszGR/+9DcEIIi5QZcRZa24Riz88BeBEIqoJf2ANA=
Thread-Topic [PATCHv2] staging: most: replace multiple if..else with table lookup
Thread-Index AQHRQU2FkHKLKfeyo0Si/S/RD+N/5Q==
Accept-Language en-US
Content-Language en-US
Authentication-Results spf=none (sender IP is ) smtp.mailfrom=hgujulan@visteon.com;
X-Ms-Exchange-Messagesentrepresentingtype 1
X-Originating-IP [91.212.132.116]
X-Microsoft-Exchange-Diagnostics 1;DB5PR06MB1576;5:A1RFszY72sEJleDyDC3HVVwWu9gH4J+TLAzoczCtOgQJBUK/NOlTlMAn1r9vMepgxC72l+9T99RB0zLR1Wp+jfRqSZwPvqTu/oeacw3fZUqnMq+G4fMsVnO8mIU6x87EkfEP46LFdjsAwb7ZPSs3Nw==;24:ixU291k9/WogmHmbSMVBcJLxXcydhBOB8LkqkMv+KFpS3+B1U+XGBzmJ2y4VH1MBS7NFphRQhwKZCEx4tsmtCW8s/87ZgTGsknmPut2JQf4=
X-Microsoft-Antispam UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB5PR06MB1576;
X-Microsoft-Antispam-Prvs <DB5PR06MB157617FF0F098428117A16AFCFFB0@DB5PR06MB1576.eurprd06.prod.outlook.com>
X-Exchange-Antispam-Report-Test UriScan:(208512329853888);
X-Exchange-Antispam-Report-Cfa-Test BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(10201501046)(3002001);SRVR:DB5PR06MB1576;BCL:0;PCL:0;RULEID:;SRVR:DB5PR06MB1576;
X-Forefront-Prvs 08041D247D
X-Forefront-Antispam-Report SFV:NSPM;SFS:(10019020)(6009001)(199003)(189002)(229853001)(92566002)(2201001)(106116001)(66066001)(33716001)(105586002)(33656002)(106356001)(586003)(102836003)(101416001)(19580405001)(11100500001)(1220700001)(1096002)(1076002)(40100003)(54356999)(5001770100001)(5004730100002)(19580395003)(50986999)(5001960100002)(97736004)(189998001)(87936001)(5002640100001)(77096005)(3846002)(2900100001)(5008740100001)(122556002)(2501003)(2860100001)(86362001)(6116002)(81156007)(10400500002);DIR:OUT;SFP:1102;SCL:1;SRVR:DB5PR06MB1576;H:DB5PR06MB1573.eurprd06.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en;
Received-Spf None (protection.outlook.com: visteon.com does not designate permitted sender hosts)
Spamdiagnosticoutput 1:23
Spamdiagnosticmetadata NSPM
Content-Type text/plain; charset="us-ascii"
Content-ID <ABD4D70D5F6DC34EA33D03318154411E@eurprd06.prod.outlook.com>
Content-Transfer-Encoding 8BIT
MIME-Version 1.0
X-Originatororg visteon.com
X-Ms-Exchange-Crosstenant-Originalarrivaltime 28 Dec 2015 08:55:37.8508 (UTC)
X-Ms-Exchange-Crosstenant-Fromentityheader Hosted
X-Ms-Exchange-Crosstenant-ID 7a147aaf-01ec-498c-80a1-e34a8c63c548
X-Ms-Exchange-Transport-Crosstenantheadersstamped DB5PR06MB1576
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 83
Organization linux.* mail to news gateway
X-Original-Cc "devel@driverdev.osuosl.org" <devel@driverdev.osuosl.org>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
X-Original-Date Mon, 28 Dec 2015 08:55:37 +0000
X-Original-Message-ID <20151228085627.GA6862@IND12F0122>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1298543

Show key headers only | View raw


From: Hari Prasath Gujulan Elango <hgujulan@visteon.com>

Replace multiple if..else if..statements with simple table lookup in two
functions.

Signed-off-by: Hari Prasath Gujulan Elango <hgujulan@visteon.com>
---
 drivers/staging/most/mostcore/core.c | 41 +++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/most/mostcore/core.c b/drivers/staging/most/mostcore/core.c
index ed1ed25..fe6705a 100644
--- a/drivers/staging/most/mostcore/core.c
+++ b/drivers/staging/most/mostcore/core.c
@@ -82,6 +82,14 @@ struct most_inst_obj {
 	struct list_head list;
 };
 
+static const struct {
+	int most_ch_data_type;
+	char *name;
+} ch_data_type[] = { { MOST_CH_CONTROL, "control\n" },
+	{ MOST_CH_ASYNC, "async\n" },
+	{ MOST_CH_SYNC, "sync\n" },
+	{ MOST_CH_ISOC_AVP, "isoc_avp\n"} };
+
 #define to_inst_obj(d) container_of(d, struct most_inst_obj, kobj)
 
 /**
@@ -414,14 +422,12 @@ static ssize_t show_set_datatype(struct most_c_obj *c,
 				 struct most_c_attr *attr,
 				 char *buf)
 {
-	if (c->cfg.data_type & MOST_CH_CONTROL)
-		return snprintf(buf, PAGE_SIZE, "control\n");
-	else if (c->cfg.data_type & MOST_CH_ASYNC)
-		return snprintf(buf, PAGE_SIZE, "async\n");
-	else if (c->cfg.data_type & MOST_CH_SYNC)
-		return snprintf(buf, PAGE_SIZE, "sync\n");
-	else if (c->cfg.data_type & MOST_CH_ISOC_AVP)
-		return snprintf(buf, PAGE_SIZE, "isoc_avp\n");
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) {
+		if (c->cfg.data_type & ch_data_type[i].most_ch_data_type)
+			return snprintf(buf, PAGE_SIZE, ch_data_type[i].name);
+	}
 	return snprintf(buf, PAGE_SIZE, "unconfigured\n");
 }
 
@@ -430,15 +436,16 @@ static ssize_t store_set_datatype(struct most_c_obj *c,
 				  const char *buf,
 				  size_t count)
 {
-	if (!strcmp(buf, "control\n")) {
-		c->cfg.data_type = MOST_CH_CONTROL;
-	} else if (!strcmp(buf, "async\n")) {
-		c->cfg.data_type = MOST_CH_ASYNC;
-	} else if (!strcmp(buf, "sync\n")) {
-		c->cfg.data_type = MOST_CH_SYNC;
-	} else if (!strcmp(buf, "isoc_avp\n")) {
-		c->cfg.data_type = MOST_CH_ISOC_AVP;
-	} else {
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) {
+		if (!strcmp(buf, ch_data_type[i].name)) {
+			c->cfg.data_type = ch_data_type[i].most_ch_data_type;
+			break;
+		}
+	}
+
+	if (i == ARRAY_SIZE(ch_data_type)) {
 		pr_info("WARN: invalid attribute settings\n");
 		return -EINVAL;
 	}
-- 
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[PATCHv2] staging: most: replace multiple if..else with table lookup "Gujulan Elango, Hari Prasath (H.)" <hgujulan@visteon.com> - 2015-12-28 10:00 +0100

csiph-web