From: Matthew Fernandez Date: Mon, 4 Jan 2021 00:16:23 +0000 (-0800) Subject: remove strcmp micro-optimizations X-Git-Tag: 2.47.0~34^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f5a326cb061866bb3beaa33c3e5169efe7fc134d;p=graphviz remove strcmp micro-optimizations Modern compilers can do these tricks themselves, so we are better off writing more straightforward readable code. --- diff --git a/cmd/mingle/minglemain.c b/cmd/mingle/minglemain.c index 85f51e9f7..8d89747af 100644 --- a/cmd/mingle/minglemain.c +++ b/cmd/mingle/minglemain.c @@ -182,9 +182,9 @@ static void init(int argc, char *argv[], opts_t* opts) fprintf (stderr, "-r arg %s must be a non-negative integer - ignored\n", optarg); break; case 'T': - if ((*optarg == 'g') && ((*(optarg+1) == 'v'))) + if (!strcmp(optarg, "gv")) opts->fmt = FMT_GV; - else if ((*optarg == 's') && (!strcmp(optarg+1,"imple"))) + else if (!strcmp(optarg,"simple")) opts->fmt = FMT_SIMPLE; else fprintf (stderr, "-T arg %s must be \"gv\" or \"simple\" - ignored\n", optarg); diff --git a/lib/ast/ast.h b/lib/ast/ast.h index f1dd53025..41baff82f 100644 --- a/lib/ast/ast.h +++ b/lib/ast/ast.h @@ -62,8 +62,8 @@ extern "C" { #define elementsof(x) (sizeof(x)/sizeof(x[0])) #define newof(p,t,n,x) ((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)calloc(1,sizeof(t)*(n)+(x))) #define oldof(p,t,n,x) ((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)malloc(sizeof(t)*(n)+(x))) -#define streq(a,b) (*(a)==*(b)&&!strcmp(a,b)) -#define strneq(a,b,n) (*(a)==*(b)&&!strncmp(a,b,n)) +#define streq(a,b) (!strcmp(a,b)) +#define strneq(a,b,n) (!strncmp(a,b,n)) #define memzero(b,n) memset(b,0,n) extern char *pathpath(char *, const char *, const char *, int); diff --git a/lib/common/emit.c b/lib/common/emit.c index 704a2a17f..6fc144d10 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -1176,10 +1176,9 @@ static int chkOrder(graph_t * g) { char *p = agget(g, "outputorder"); if (p) { - char c = *p; - if ((c == 'n') && !strcmp(p + 1, "odesfirst")) + if (!strcmp(p, "nodesfirst")) return EMIT_SORTED; - if ((c == 'e') && !strcmp(p + 1, "dgesfirst")) + if (!strcmp(p, "edgesfirst")) return EMIT_EDGE_SORTED; } return 0; diff --git a/lib/inkpot/inkpot_scheme.c b/lib/inkpot/inkpot_scheme.c index 73a174106..61a0bbb77 100644 --- a/lib/inkpot/inkpot_scheme.c +++ b/lib/inkpot/inkpot_scheme.c @@ -228,7 +228,7 @@ static inkpot_status_t inkpot_cache_get( inkpot_t *inkpot ) cache_name_idx = inkpot->cache[i].name_idx; cache_color = &TAB_STRINGS[TAB_NAMES[cache_name_idx].string_idx]; - if (cache_color[0] != color[0] || (strcmp(cache_color, color) != 0)) + if (strcmp(cache_color, color) != 0) continue; /* found */ @@ -448,7 +448,7 @@ inkpot_status_t inkpot_put ( inkpot_t *inkpot, const char *color ) for (i=0; i < inkpot->active_schemes; i++) { j = inkpot->scheme_list[i]; p = &TAB_STRINGS[TAB_ICOLORS[j].string_idx]; - if (*p != *s || strcmp(p, s) != 0) + if (strcmp(p, s) != 0) continue; /* FIXME - deal with subschemes */ first = TAB_ICOLORS[j].range_idx; diff --git a/tclpkg/gv/gv.cpp b/tclpkg/gv/gv.cpp index ad3a22bb8..3c41d5b71 100644 --- a/tclpkg/gv/gv.cpp +++ b/tclpkg/gv/gv.cpp @@ -148,7 +148,7 @@ static char* myagxget(void *obj, Agsym_t *a) val = agxget(obj, a); if (!val) return emptystring; - if (a->name[0] == 'l' && strcmp(a->name, "label") == 0 && aghtmlstr(val)) { + if (strcmp(a->name, "label") == 0 && aghtmlstr(val)) { len = strlen(val); hs = (char*)malloc(len + 3); hs[0] = '<'; @@ -177,7 +177,7 @@ static void myagxset(void *obj, Agsym_t *a, char *val) int len; char *hs; - if (a->name[0] == 'l' && val[0] == '<' && strcmp(a->name, "label") == 0) { + if (strcmp(a->name, "label") == 0 && val[0] == '<') { len = strlen(val); if (val[len-1] == '>') { hs = strdup(val+1); @@ -785,7 +785,7 @@ bool rm(Agnode_t *n) if (!n) return false; // removal of the protonode is not permitted - if (agnameof(n)[0] == '\001' && strcmp (agnameof(n), "\001proto") ==0) + if (strcmp (agnameof(n), "\001proto") ==0) return false; agdelete(agraphof(n), n); return true; @@ -796,8 +796,8 @@ bool rm(Agedge_t *e) if (!e) return false; // removal of the protoedge is not permitted - if ((agnameof(aghead(e))[0] == '\001' && strcmp (agnameof(aghead(e)), "\001proto") == 0) - || (agnameof(agtail(e))[0] == '\001' && strcmp (agnameof(agtail(e)), "\001proto") == 0)) + if (strcmp (agnameof(aghead(e)), "\001proto") == 0 + || strcmp (agnameof(agtail(e)), "\001proto") == 0) return false; agdelete(agroot(agraphof(aghead(e))), e); return true; diff --git a/tclpkg/tcldot/tcldot-util.c b/tclpkg/tcldot/tcldot-util.c index f9d6de351..6f2f5d2ac 100644 --- a/tclpkg/tcldot/tcldot-util.c +++ b/tclpkg/tcldot/tcldot-util.c @@ -127,7 +127,7 @@ static void myagxset(void *obj, Agsym_t *a, char *val) int len; char *hs; - if (a->name[0] == 'l' && val[0] == '<' && strcmp(a->name, "label") == 0) { + if (strcmp(a->name, "label") == 0 && val[0] == '<') { len = strlen(val); if (val[len-1] == '>') { hs = strdup(val+1);