git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: "Shawn O. Pearce" <spearce@spearce.org>,
	Junio C Hamano <junkio@cox.net>,
	git@vger.kernel.org
Subject: Re: [PATCH] Correct dir.c to compile on Solaris 9
Date: Sun, 15 Apr 2007 23:03:12 +0200	[thread overview]
Message-ID: <200704152303.12435.Josef.Weidendorfer@gmx.de> (raw)
In-Reply-To: <Pine.LNX.4.64.0704151824240.18846@racer.site>

On Sunday 15 April 2007, Johannes Schindelin wrote:
> On Sun, 15 Apr 2007, Shawn O. Pearce wrote:
> >  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).

Or faster. When the table gives a cache miss and has to be
loaded from main memory, I am quite sure that 5 compares in a row are
faster than the cache miss.

Actually, with the switch, the compiler is free to implement it with a
table (and gcc usually does this, probably even using a substantially
smaller table). The table-based check in contrast looks
like some kind of micro-optimization which makes the code IMHO more
difficult to read, and which only would be justified with meassured
improvements.

Josef

  reply	other threads:[~2007-04-15 21:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-15  4:33 [PATCH] Correct dir.c to compile on Solaris 9 Shawn O. Pearce
2007-04-15 16:25 ` Johannes Schindelin
2007-04-15 21:03   ` Josef Weidendorfer [this message]
2007-04-15 21:54     ` Robin Rosenberg
2007-04-15 22:48       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200704152303.12435.Josef.Weidendorfer@gmx.de \
    --to=josef.weidendorfer@gmx.de \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).