From: Matthew Fernandez Date: Fri, 16 Jul 2021 03:44:04 +0000 (-0700) Subject: replace 1-byte strstr calls with strchr X-Git-Tag: 2.49.0~55^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=38c3d26191db8479943d08e1e646190c97a02792;p=graphviz replace 1-byte strstr calls with strchr This change has no effect on functionality, but strchr is cheaper to call and equivalent to these strstr calls. This likely makes no difference in an optimized build as modern compilers can see this transformation is possible themselves. However, this change may assist older compilers or accelerate unoptimized builds. --- diff --git a/lib/edgepaint/edge_distinct_coloring.c b/lib/edgepaint/edge_distinct_coloring.c index 977441395..48fa75777 100644 --- a/lib/edgepaint/edge_distinct_coloring.c +++ b/lib/edgepaint/edge_distinct_coloring.c @@ -9,6 +9,7 @@ *************************************************************************/ #include #include +#include #include #include #include @@ -69,7 +70,7 @@ static int splines_intersect(int dim, int u1, int v1, int u2, int v2, ns1++; } iter1++; - xsplines1 = strstr(xsplines1, " "); + xsplines1 = strchr(xsplines1, ' '); if (!xsplines1) break; xsplines1++; if (ns1*dim >= len1){ @@ -107,7 +108,7 @@ static int splines_intersect(int dim, int u1, int v1, int u2, int v2, ns2++; } iter2++; - xsplines2 = strstr(xsplines2, " "); + xsplines2 = strchr(xsplines2, ' '); if (!xsplines2) break; xsplines2++; if (ns2*dim >= len2){ diff --git a/lib/edgepaint/lab.c b/lib/edgepaint/lab.c index f2bb2b3b4..63f349515 100644 --- a/lib/edgepaint/lab.c +++ b/lib/edgepaint/lab.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -233,7 +234,7 @@ void color_blend_rgb2lab(char *color_list, const int maxpoints, double **colors0 if (maxpoints <= 0) return; cl = color_list; - while ((cl=strstr(cl, ",")) != NULL){ + while ((cl=strchr(cl, ',')) != NULL){ cl++; nc++; } lab = malloc(sizeof(color_lab)*MAX(nc,1)); @@ -245,7 +246,7 @@ void color_blend_rgb2lab(char *color_list, const int maxpoints, double **colors0 if (sscanf(cl,"#%02X%02X%02X", &r, &g, &b) != 3) break; rgb.r = r; rgb.g = g; rgb.b = b; lab[nc++] = RGB2LAB(rgb); - } while ((cl=strstr(cl, ",")) != NULL); + } while ((cl=strchr(cl, ',')) != NULL); dists = malloc(sizeof(double)*MAX(1, nc)); dists[0] = 0; diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index 1773c4828..2d1219dc7 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -458,7 +458,7 @@ void gvrender_set_pencolor(GVJ_t * job, char *name) gvcolor_t *color = &(job->obj->pencolor); char *cp = NULL; - if ((cp = strstr(name, ":"))) /* if its a color list, then use only first */ + if ((cp = strchr(name, ':'))) /* if its a color list, then use only first */ *cp = '\0'; if (gvre) { gvrender_resolve_color(job->render.features, name, color); @@ -475,7 +475,7 @@ void gvrender_set_fillcolor(GVJ_t * job, char *name) gvcolor_t *color = &(job->obj->fillcolor); char *cp = NULL; - if ((cp = strstr(name, ":"))) /* if its a color list, then use only first */ + if ((cp = strchr(name, ':'))) /* if its a color list, then use only first */ *cp = '\0'; if (gvre) { gvrender_resolve_color(job->render.features, name, color); diff --git a/plugin/gd/gvrender_gd.c b/plugin/gd/gvrender_gd.c index 9822eae38..d2dc9a4cd 100644 --- a/plugin/gd/gvrender_gd.c +++ b/plugin/gd/gvrender_gd.c @@ -297,7 +297,7 @@ void gdgen_text(gdImagePtr im, pointf spf, pointf epf, int fontcolor, double fon strex.flags = gdFTEX_RESOLUTION; strex.hdpi = strex.vdpi = fontdpi; - if (strstr(fontname, "/")) + if (strchr(fontname, '/')) strex.flags |= gdFTEX_FONTPATHNAME; else strex.flags |= gdFTEX_FONTCONFIG; diff --git a/plugin/gd/gvtextlayout_gd.c b/plugin/gd/gvtextlayout_gd.c index 21a7506f4..727aab928 100644 --- a/plugin/gd/gvtextlayout_gd.c +++ b/plugin/gd/gvtextlayout_gd.c @@ -127,7 +127,7 @@ static boolean gd_textlayout(textspan_t * span, char **fontpath) strex.flags = gdFTEX_RETURNFONTPATHNAME | gdFTEX_RESOLUTION; strex.hdpi = strex.vdpi = POINTS_PER_INCH; - if (strstr(fontname, "/")) + if (strchr(fontname, '/')) strex.flags |= gdFTEX_FONTPATHNAME; else strex.flags |= gdFTEX_FONTCONFIG;