Re: [PATCH 11/13] strbuf: add strbuf_add*_urlencode
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:52:32
Jeff King [off-list ref] writes:
On Wed, Nov 30, 2011 at 12:26:20AM +0100, René Scharfe wrote:quoted
quoted
quoted
quoted
+static int is_rfc3986_reserved(char ch) +{ + switch (ch) { + case '!': case '*': case '\'': case '(': case ')': case ';': + case ':': case '@': case '&': case '=': case '+': case '$': + case ',': case '/': case '?': case '#': case '[': case ']': + return 1; + }[...] Sorry for my bikeshedding, but I'd paint it like this: return !!strchr("!*'();:@&=+$,/?#[]", ch);I was always under the impression that computed jumps via "switch" would out-perform even an optimized strchr. Of course, I never tested. And I doubt performance is even relevant here, and I admit I don't care overly much. I find them both equally readable. I'm going to leave it as-is unless somebody else wants to say "I strongly prefer version X".
I find the switch/case one much easier to read and count, especially since all the choices are essentially line-noise characters. Just make sure you indent it correctly ;-)