From b0101b5ce7de958bad5c043ce50ae422fd35ed46 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Wed, 14 Jul 2021 20:58:50 -0700 Subject: [PATCH] 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. --- lib/expr/exeval.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) 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); } /* -- 2.40.0