From: "George Spelvin" <linux@horizon.com>
To: srostedt@redhat.com, peterz@infradead.org
Cc: tj@kernel.org, linux@horizon.com, linux-kernel@vger.kernel.org,
andi@firstfloor.org
Subject: Re: [RFC] globmatch() helper function
Date: Thu, 18 Dec 2008 03:00:27 -0500 [thread overview]
Message-ID: <20081218080027.27011.qmail@science.horizon.com> (raw)
In-Reply-To: <1229528856.30177.4.camel@localhost.localdomain>
Steven Rostedt <srostedt@redhat.com> wrote:
> I need to look at your code (I would like a generalized glob feature for
> user input). Can you accomplish the same with using a loop instead of
> recursion?
Unfortunately, no. Matching multiple * characters inherently requires
backtracking, and backtracking requires a stack.
I could make it a finite-depth explicit stack rather than using
the C stack implicitly, but it doesn't save much on reasonable
patterns.
But if you want it for user input, I can work at making it more
robust. What are your sped needs?
0 - Runs once only, speed unimportant
1 - Runs several thousand times (counting all NxM matches), would like
it to not be too slow.
2 - Run a thousand times per second, but it's a debug feature so
a speed hit is acceptable.
3 - Common code path, maybe rearchitect to save time.
4 - Kernel fast path, every cycle counts!
There are quite a few things (with commensurate code size increases)
that can't help the big-O worst-case performance, but improve the average
case considerably.
One thing I don't do that's quite possible is to find the fixed-length
head and tail of the pattern (the parts before the first * and after the
last) and match those before dealing with the annoying middle.
That would avoid all backtracking in cases with a single *, and make a
good pre-filter before doing anything expensive in the middle.
H'm... I think there's an equivalent and more general version based on
the number of characters a pattern matches. Any pattern's length is
N characters, plus a flag indicating if that's fixed or just a minimum.
When matching a *, compute the length of the following pattern and only
try matching cases which have the right length.
If we need to do a lot of matching against a single pattern, it's possible
to preprocess it to find the fixed-length spans and their lengths.
(The current blacklist application is exactly the opposite: matching
one string against a list of patterns.)
next prev parent reply other threads:[~2008-12-18 8:00 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-17 10:42 George Spelvin
2008-12-17 13:28 ` Andi Kleen
2008-12-17 15:15 ` Peter Zijlstra
2008-12-17 15:47 ` Steven Rostedt
2008-12-17 16:15 ` Andi Kleen
2008-12-18 8:00 ` George Spelvin [this message]
2008-12-18 8:55 ` George Spelvin
2008-12-18 19:53 ` Casey Dahlin
2008-12-18 21:53 ` George Spelvin
2008-12-17 16:04 ` George Spelvin
2008-12-17 16:13 ` Steven Rostedt
2008-12-17 16:22 ` Tejun Heo
2008-12-17 16:31 ` Steven Rostedt
2008-12-17 16:33 ` Tejun Heo
2008-12-17 16:36 ` Peter Zijlstra
2008-12-17 16:45 ` Tejun Heo
2008-12-17 16:37 ` Steven Rostedt
2008-12-17 16:51 ` Andi Kleen
2008-12-17 16:54 ` Steven Rostedt
2008-12-17 15:37 ` George Spelvin
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=20081218080027.27011.qmail@science.horizon.com \
--to=linux@horizon.com \
--cc=andi@firstfloor.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=srostedt@redhat.com \
--cc=tj@kernel.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
all inboxes | Powered by JetHome®