From: Matthew Fernandez Date: Thu, 15 Jul 2021 03:58:50 +0000 (-0700) Subject: str_xor: [nfc] rewrite in more modern C99 style X-Git-Tag: 2.49.0~52^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b0101b5ce7de958bad5c043ce50ae422fd35ed46;p=graphviz str_xor: [nfc] rewrite in more modern C99 style Upcoming changes will improve the efficiency of this function and decrease its coupling with other operations. Rather than introduce these new changes in a differing style, this preparatory commit rewrites the existing functionality in this style first, without affecting its behavior. Related to #1873, #1998. --- diff --git a/lib/expr/exeval.c b/lib/expr/exeval.c index 50af824aa..5e2c9b863 100644 --- a/lib/expr/exeval.c +++ b/lib/expr/exeval.c @@ -644,19 +644,19 @@ static char *str_and(Expr_t *ex, const char *l, const char *r) { * string xor */ -static char* -str_xor(Expr_t* ex, char* l, char* r) -{ - int c; - char* s = l; +static char *str_xor(Expr_t *ex, const char *l, const char *r) { - while ((c = *s++)) - if (!strchr(r, c) && !strchr(s, c)) - sfputc(ex->tmp, c); - while ((c = *r++)) - if (!strchr(l, c) && !strchr(r, c)) - sfputc(ex->tmp, c); - return exstash(ex->tmp, ex->ve); + for (const char *p = l; *p != '\0'; ++p) { + if (strchr(r, *p) == NULL && strchr(p + 1, *p) == NULL) { + sfputc(ex->tmp, *p); + } + } + for (const char *p = r; *p != '\0'; ++p) { + if (strchr(l, *p) == NULL && strchr(p + 1, *p) == NULL) { + sfputc(ex->tmp, *p); + } + } + return exstash(ex->tmp, ex->ve); } /*