Re: [PATCH] Correct dir.c to compile on Solaris 9
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Apr 15, 2007, 16:25 UTC
- Message-ID
- <Pine.LNX.4.64.0704151824240.18846@racer.site>
- In-Reply-To
- <20070415043328.GA17285@spearce.org>
Hi,
On Sun, 15 Apr 2007, Shawn O. Pearce wrote:
Show 35 quoted lines
> The compiler on my Solaris 9 system doesn't understand
> the array initialization syntax used here in dir.c.
>
> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
> ---
> dir.c | 11 +++++------
> 1 files changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/dir.c b/dir.c
> index 7426fde..038fd82 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -423,18 +423,17 @@ 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])
> + switch (c) {
> + case 0: case '?':
> + case '\\': case '*':
> + case '[':
> return len;
> + }
> }
> }You are replacing a table-based check with a switch based, which might be substantially slower (depends on how often cmp_name() is called).
Maybe there is another way to initialize the table (and make it static to begin with)?
Ciao, Dscho