From: Jeff King Date: Mon, 09 Mar 2026 19:08:23 GMT Subject: Re: [PATCH v1 2/2] list-objects-filter-options: avoid strbuf_split_str() Message-ID: <20260309190823.GB309867@coredump.intra.peff.net> In-Reply-To: <20260308180359.31188-3-deveshigurgaon@gmail.com> On Sun, Mar 08, 2026 at 06:03:59PM +0000, Deveshi Dwivedi wrote: > + while (*p && !result) { > + const char *sep = strchr(p, '+'); > + size_t len = sep ? (size_t)(sep - p + 1) : strlen(p); > + char *sub = xmemdupz(p, len); The cast to size_t made me look twice to see if something tricky was going on. We don't usually bother explicitly casting from a ptrdiff_t into a size_t. However, might this all be simpler with strchrnul? Something like: const char *end = strchrnul(p, '+'); char *sub = xmemdupz(p, end - p); ...parse sub... if (!*end) break; /* found NUL at end of string */ p = end + 1; Notice I cut off the "+" when we find it, because I think... > + /* strip '+' separator, but only when more sub-specs follow */ > + if (sep && *(sep + 1)) > + sub[len - 1] = '\0'; ...this is wrong. I know you are matching what the current code does, but it does not match the documentation, and does not actually make any sense in practice. Other than that, this looks nice, and I am happy to see more strbuf_split() calls going away. I think you could in theory drop the xmemdupz() here, too, and feed the ptr/len combo into parse_combine_subfilter(), which then percent-decodes into a newly allocated buffer. But it is probably not worth trying to squeeze out one extra allocation here. It is not like people have huge lists of combined filters; we'd expect to see a couple at most. -Peff