Re: [PATCH] grep: do not do external grep on skip-worktree entries
- From
Linus Torvalds <torvalds@linux-foundation.org>
- Date
- Jan 11, 2010, 21:24 UTC
- Message-ID
- <alpine.LFD.2.00.1001111315470.17145@localhost.localdomain>
- In-Reply-To
- <4c8ef71001111307q6679039ajbef22f2e1748df56@mail.gmail.com>
On Mon, 11 Jan 2010, Fredrik Kuivinen wrote:
Show 5 quoted lines
> > Another option is to use memmem instead. As we know the length of the > buffer already it should be a slight improvement over strstr for > everyone. memmem may cause some portability problems though as it is a > GNU extension.
I'd almost prefer to just drop the strstr entirely.
It's not actually all *that* big a win, even on my machine. I get
- strstr:
real 0m0.309s
user 0m0.168s
sys 0m0.136s- regexec:
real 0m0.410s user 0m0.220s sys 0m0.116s
so yeah, it's slower, but not by a huge degree. With strstr, "git grep" actually beats the external grep for me, but I don't really care. It's already way better than it used to be - and clearly strstr has a lot of potential problems.
Sure memmem() might be better for you than strstr, but on the other hand, it might easily be worse than strstr for others - and not just from a portability standpoint. Is memmem() optimized to take advantage of SSE4.2? I suspect it is not, exactly _because_ it's a GNU extension, so Intel hasn't published optimized sample code for people to use.
So I would argue against even bothering to try memmem. Especially since in your case, regexec() is apparently faster than memmem _anyway_. I expect that it is for me too, but I'm too lazy to check.
Linus