You might get some minor joy by:
- Compiling your regexps and saving them. See qr in perldoc perlop.
- If each line can only match one of these typedefs, make sure you exit the typedef loop when you find a match.
- In combination with the previous, if you have some typedefs which are more likely to occur, order the typedefs array with the most likely at the front (for early exit).
In combination:
my @typedefs = qw(...sorted list of typedefs, common ones first...);
my @regexes = map { qr{$_} } @typedefs;
REGEX:
foreach my $regex (@regexes) {
if ($line =~ $regex) {
# found typedef so do work
last REGEX; # Stop looking
}
}
Ah...if you want to perform the same action, you can munge all your typedefs together into one regex.
my @typedefs = qw(...sorted list of typedefs, common ones first...);
# Make a big '(a|b|c|...)' regex str
# Should probably do some quoting here.
my $regexStr = "(" . join("|", @typedefs) . ")";
my $regex = qr{$regexStr};
if ($line =~ $regex) {
# found typedef so do work
}
That should help a bit, since you're now handling all the alternatives in the regex engine, i.e. looping in C not perl.
UPDATE: in case it's not obvious, you want to produce the @regex array or $regex once, before looping through all your lines. Don't do it per line :-)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|