Thread (2 messages) 2 messages, 2 authors, 2024-05-30

Re: [PATCH 12/19] remote-curl: avoid assigning string constant to non-const variable

From: Patrick Steinhardt <hidden>
Date: 2024-05-30 11:30:41

On Wed, May 29, 2024 at 01:21:47PM -0700, Junio C Hamano wrote:
Patrick Steinhardt [off-list ref] writes:
quoted
 		} 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.
Indeed, that version looks nicer. Thanks!

Patrick

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help