note
jbert
You might get some minor joy by:
<ul>
<li>Compiling your regexps and saving them. See <c>qr</c> in perldoc perlop.
<li>If each line can only match one of these typedefs, make sure you exit the typedef loop when you find a match.
<li>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).
</ul>
In combination:
<c>
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
}
}
</c>
Ah...if you want to perform the same action, you can munge all your typedefs together into one regex.
<c>
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
}
</c>
That should help a bit, since you're now handling all the alternatives in the regex engine, i.e. looping in C not perl.
<p>
UPDATE: in case it's not obvious, you want to produce the <c>@regex</c> array or <c>$regex</c> once, before looping through all your lines. Don't do it per line :-)
661292
661292