[PATCH 3/3] vcs-svn: use switch rather than cascading ifs
- From
David Barr <david.barr@cordelta.com>
- Date
- Mar 21, 2011, 01:26 UTC
- Message-ID
- <1300670777-17197-3-git-send-email-david.barr@cordelta.com>
- In-Reply-To
- <1300670777-17197-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> --- vcs-svn/svndump.c | 38 +++++++++++++++++++++++++++++--------- 1 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/vcs-svn/svndump.c b/vcs-svn/svndump.c index f03e8cf..fe14ce2 100644 --- a/vcs-svn/svndump.c +++ b/vcs-svn/svndump.c @@ -350,25 +350,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")) { + break; + case sizeof("change"): + if (constcmp(val, "change")) + break; node_ctx.action = NODEACT_CHANGE; - } else if (!strcmp(val, "replace")) { + break; + case sizeof("delete"): + if (!constcmp(val, "delete")) { + node_ctx.action = NODEACT_DELETE; + break; + } + 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