Re: [PATCH 12/19] remote-curl: avoid assigning string constant to non-const variable
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 29, 2024, 20:21 UTC
- Message-ID
- <xmqq5xuwweqs.fsf@gitster.g>
- In-Reply-To
- <00b4a7dbbcdfd8a0f7b4beb4ecaf272257838460.1716983704.git.ps@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 12 quoted lines
> } else if (skip_prefix(buf.buf, "option ", &arg)) {
> + const char *value = strchr(arg, ' ');
> + size_t arglen;
> int result;
>
> + if (value) {
> + arglen = value - arg;
> + value++;
> + } else {
> + arglen = strlen(arg);
> value = "true";
> + }There is a micro optimization opportunity here.
const char *value = strchrnul(arg, ' '); size_t arglen = value - arg;
if (*value) value++; /* skip over SP */ else value = "true";
But other than that, very cleanly done.