History

cgit.c: Use "else" for mutually exclusive branches

When parsing command line arguments, no pair of command line options can ever match simultaneously. Use "else if" blocks to reflect this. This change improves both readability and speed.

Lukas Fleischer committed 12 years ago

Commit 441e7481 parent e7116791 file · +10 −19Browse files

Unified · Split

cgit.c+10−19
@@ -865,35 +865,26 @@ static void cgit_parse_args(int argc, const char **argv) · 864 unmodified lines
865865 for (i = 1; i < argc; i++) {
866866 if (!prefixcmp(argv[i], "--cache=")) {
867867 ctx.cfg.cache_root = xstrdup(argv[i] + 8);
868− }
869− if (!strcmp(argv[i], "--nocache")) {
868+ } else if (!strcmp(argv[i], "--nocache")) {
870869 ctx.cfg.nocache = 1;
871− }
872− if (!strcmp(argv[i], "--nohttp")) {
870+ } else if (!strcmp(argv[i], "--nohttp")) {
873871 ctx.env.no_http = "1";
874− }
875− if (!prefixcmp(argv[i], "--query=")) {
872+ } else if (!prefixcmp(argv[i], "--query=")) {
876873 ctx.qry.raw = xstrdup(argv[i] + 8);
877− }
878− if (!prefixcmp(argv[i], "--repo=")) {
874+ } else if (!prefixcmp(argv[i], "--repo=")) {
879875 ctx.qry.repo = xstrdup(argv[i] + 7);
880− }
881− if (!prefixcmp(argv[i], "--page=")) {
876+ } else if (!prefixcmp(argv[i], "--page=")) {
882877 ctx.qry.page = xstrdup(argv[i] + 7);
883− }
884− if (!prefixcmp(argv[i], "--head=")) {
878+ } else if (!prefixcmp(argv[i], "--head=")) {
885879 ctx.qry.head = xstrdup(argv[i] + 7);
886880 ctx.qry.has_symref = 1;
887− }
888− if (!prefixcmp(argv[i], "--sha1=")) {
881+ } else if (!prefixcmp(argv[i], "--sha1=")) {
889882 ctx.qry.sha1 = xstrdup(argv[i] + 7);
890883 ctx.qry.has_sha1 = 1;
891− }
892− if (!prefixcmp(argv[i], "--ofs=")) {
884+ } else if (!prefixcmp(argv[i], "--ofs=")) {
893885 ctx.qry.ofs = atoi(argv[i] + 6);
894− }
895− if (!prefixcmp(argv[i], "--scan-tree=") ||
896− !prefixcmp(argv[i], "--scan-path=")) {
886+ } else if (!prefixcmp(argv[i], "--scan-tree=") ||
887+ !prefixcmp(argv[i], "--scan-path=")) {
897888 /* HACK: the global snapshot bitmask defines the
898889 * set of allowed snapshot formats, but the config
899890 * file hasn't been parsed yet so the mask is