Thread (4 messages) flat view 4 messages, 3 authors, 2016-06-15

Re: [PATCH] dir.c: avoid c99 array initialization

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:45:15

Possibly related (same subject, not in this thread)

"Shawn O. Pearce" [off-list ref] writes:
Alex Riesen [off-list ref] wrote:
quoted
For just these 5 values it is likely more effective to just use
a conditional statement (less stack requested, less likely
some stupid compiler tries to optimize it wrongly).
And just as readable.
diff --git a/dir.c b/dir.c
index 92452eb..1cf5985 100644
--- a/dir.c
+++ b/dir.c
@@ -680,17 +680,12 @@ static int cmp_name(const void *p1, const void *p2)
  */
 static int simple_length(const char *match)
 {
-	const char special[256] = {
-		[0] = 1, ['?'] = 1,
-		['\\'] = 1, ['*'] = 1,
-		['['] = 1
-	};
 	int len = -1;

 	for (;;) {
 		unsigned char c = *match++;
 		len++;
-		if (special[c])
+		if (!c || '?' == c || '\\' == c || '*' == c || '[' == c)
I am reminded of a year old thread with my patch to this:

  http://kerneltrap.org/mailarchive/git/2007/4/15/243541

The patch never applied.  I wonder why.  Was it just Dscho's comment?
I think it was an unanswered question about stealing one bit from
ctype.c::sane_ctype[] that kept the discussion in limbo.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help