From f9ed40f2742263b3a1023bedee4139b4b18f0a86 Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Sat, 14 Feb 2015 17:29:22 +0100 Subject: [PATCH] Refactor: Use if for two-way branching; Compare against 0 explicitly I think that the use of switch for the two-way branches could have been a performance optimization. I think it's clearer to use if, especially in the fall-through case. As setjmp() is known to return with either 0 or something else, we should compare against 0 and not against some define (for which I again and again wonder if it stands for 0 or for 1). --- uip/mhl.c | 27 ++++++++++++--------------- uip/prompter.c | 2 +- uip/send.c | 8 ++------ 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/uip/mhl.c b/uip/mhl.c index fedf78f..8c2e4af 100644 --- a/uip/mhl.c +++ b/uip/mhl.c @@ -573,8 +573,7 @@ process(char *fname, int ofilen, int ofilec) FILE *fp = NULL; struct mcomp *c1; - switch (setjmp(env)) { - case OK: + if (setjmp(env) == 0) { if (fname) { fp = mhl_action ? (*mhl_action) (fname) : fopen(fname, "r"); @@ -589,20 +588,18 @@ process(char *fname, int ofilen, int ofilec) } SIGNAL(SIGINT, intrser); mhlfile(fp, fname, ofilen, ofilec); - /* FALL THROUGH! */ - default: - SIGNAL(SIGINT, SIG_IGN); - if (mhl_action == NULL && fp != stdin) - fclose(fp); - if (holder.c_text) { - free(holder.c_text); - holder.c_text = NULL; - } - free_queue(&msghd, &msgtl); - for (c1 = fmthd; c1; c1 = c1->c_next) - c1->c_flags &= ~HDROUTPUT; - break; } + + SIGNAL(SIGINT, SIG_IGN); + if (mhl_action == NULL && fp != stdin) + fclose(fp); + if (holder.c_text) { + free(holder.c_text); + holder.c_text = NULL; + } + free_queue(&msghd, &msgtl); + for (c1 = fmthd; c1; c1 = c1->c_next) + c1->c_flags &= ~HDROUTPUT; } diff --git a/uip/prompter.c b/uip/prompter.c index 823760e..ef33db9 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -269,7 +269,7 @@ getln(char *buffer, int n) *cp = '\0'; switch (setjmp(sigenv)) { - case OK: + case 0: wtuser = 1; break; diff --git a/uip/send.c b/uip/send.c index ed6b08d..13ae761 100644 --- a/uip/send.c +++ b/uip/send.c @@ -289,8 +289,7 @@ sendsbr(char **vec, int vecp, char *drft, struct stat *st) } done=armed_done; - switch (setjmp(env)) { - case OK: + if (setjmp(env) == 0) { status = sendaux(vec, vecp, drft, st) ? NOTOK : OK; if (status == OK) { /* move original draft to +trash folder */ @@ -305,11 +304,8 @@ sendsbr(char **vec, int vecp, char *drft, struct stat *st) dup2(dupfd, 0); close(dupfd); } - break; - - default: + } else { status = DONE; - break; } done=exit; -- 1.7.10.4