[git commit master 1/1] mpstat: small code shrink

Denys Vlasenko vda.linux at googlemail.com
Fri Jul 30 01:56:02 UTC 2010


commit: http://git.busybox.net/busybox/commit/?id=5e87c2ef150275ddb8fd7be0397881eeeb3bb081
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Maksym Kryzhanovskyy <xmaks at email.cz>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 procps/mpstat.c |   16 +++++++---------
 1 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/procps/mpstat.c b/procps/mpstat.c
index 125bb3d..b0d187e 100644
--- a/procps/mpstat.c
+++ b/procps/mpstat.c
@@ -954,16 +954,14 @@ int mpstat_main(int UNUSED_PARAM argc, char **argv)
 	}
 
 	if (opt & OPT_INTS) {
-		if (strcmp(opt_irq_fmt, "ALL") == 0)
-			G.options |= D_IRQ_SUM + D_IRQ_CPU + D_SOFTIRQS;
-		else if (strcmp(opt_irq_fmt, "CPU") == 0)
-			G.options |= D_IRQ_CPU;
-		else if (strcmp(opt_irq_fmt, "SUM") == 0)
-			G.options |= D_IRQ_SUM;
-		else if (strcmp(opt_irq_fmt, "SCPU") == 0)
-			G.options |= D_SOFTIRQS;
-		else
+		static const char v[] = {
+			D_IRQ_CPU, D_IRQ_SUM, D_SOFTIRQS,
+			D_IRQ_SUM + D_IRQ_CPU + D_SOFTIRQS
+		};
+		i = index_in_strings("CPU\0SUM\0SCPU\0ALL\0", opt_irq_fmt);
+		if (i == -1)
 			bb_show_usage();
+		G.options |= v[i];
 	}
 
 	if ((opt & OPT_UTIL) /* -u? */
-- 
1.7.1



More information about the busybox-cvs mailing list