[PATCH 06/11] vcs-svn: use switch rather than cascading ifs
- From
David Barr <david.barr@cordelta.com>
- Date
- Mar 21, 2011, 23:49 UTC
- Message-ID
- <1300751400-7427-7-git-send-email-david.barr@cordelta.com>
- In-Reply-To
- <1300751400-7427-1-git-send-email-david.barr@cordelta.com>
In the spirit of the last two changes: Switch on length and use constcmp for parsing headers with restricted values.
Signed-off-by: David Barr <david.barr@cordelta.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> --- vcs-svn/svndump.c | 40 ++++++++++++++++++++++++++++++---------- 1 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/vcs-svn/svndump.c b/vcs-svn/svndump.c index 3ad48e5..7b5b5ec 100644 --- a/vcs-svn/svndump.c +++ b/vcs-svn/svndump.c @@ -343,25 +343,45 @@ void svndump_read(const char *url) } if (constcmp(t + strlen("Node-"), "kind")) continue; - if (!strcmp(val, "dir")) + switch (strlen(val) + 1) { + case sizeof("dir"): + if (constcmp(val, "dir")) + break; node_ctx.type = REPO_MODE_DIR; - else if (!strcmp(val, "file")) + break; + case sizeof("file"): + if (constcmp(val, "file")) + break; node_ctx.type = REPO_MODE_BLB; - else + break; + default: fprintf(stderr, "Unknown node-kind: %s\n", val); + } break; case sizeof("Node-action"): if (constcmp(t, "Node-action")) continue; - if (!strcmp(val, "delete")) { - node_ctx.action = NODEACT_DELETE; - } else if (!strcmp(val, "add")) { + switch (strlen(val) + 1) { + case sizeof("add"): + if (constcmp(val, "add")) + break; node_ctx.action = NODEACT_ADD; - } else if (!strcmp(val, "change")) { - node_ctx.action = NODEACT_CHANGE; - } else if (!strcmp(val, "replace")) { + break; + case sizeof("change"): + if (!constcmp(val, "change")) { + node_ctx.action = NODEACT_CHANGE; + break; + } + if (constcmp(val, "delete")) + break; + node_ctx.action = NODEACT_DELETE; + break; + case sizeof("replace"): + if (constcmp(val, "replace")) + break; node_ctx.action = NODEACT_REPLACE; - } else { + break; + default: fprintf(stderr, "Unknown node-action: %s\n", val); node_ctx.action = NODEACT_UNKNOWN; }
-- 1.7.3.2.846.gf4b062