You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2005/01/20 05:38:45 UTC
svn commit: r125710 - /spamassassin/trunk/masses/hit-frequencies
Author: jm
Date: Wed Jan 19 20:38:44 2005
New Revision: 125710
URL: http://svn.apache.org/viewcvs?view=rev&rev=125710
Log:
make an eval out of the inner loop of h-f; 20% faster
Modified:
spamassassin/trunk/masses/hit-frequencies
Modified: spamassassin/trunk/masses/hit-frequencies
Url: http://svn.apache.org/viewcvs/spamassassin/trunk/masses/hit-frequencies?view=diff&rev=125710&p1=spamassassin/trunk/masses/hit-frequencies&r1=125709&p2=spamassassin/trunk/masses/hit-frequencies&r2=125710
==============================================================================
--- spamassassin/trunk/masses/hit-frequencies (original)
+++ spamassassin/trunk/masses/hit-frequencies Wed Jan 19 20:38:44 2005
@@ -358,34 +358,76 @@
my $caught;
my $rules;
- while (<IN>) {
- next unless (!$opt_M || /$opt_M/o);
- next if ($opt_X && /$opt_X/o);
-
- ($caught, undef, undef, $rules) = split;
-
- next unless ($caught eq 'Y' || $caught eq '.') && $rules;
- next if ($opt_f && !(($caught eq 'Y') xor $isspam));
-
- if ($isspam) {
- $num_spam++;
- foreach my $r (split(/,/, $rules)) {
+ # this is very speed-sensitive code. remove all possible
+ # conditionals using an eval('..').
+ my $evalstr = '
+ while (<IN>) {
+ ';
+
+ if ($opt_M) {
+ $evalstr .= '
+ next unless /$opt_M/o;
+ ';
+ }
+ if ($opt_X) {
+ $evalstr .= '
+ next if /$opt_X/o;
+ ';
+ }
+
+ # note: doing the match with a regexp shaves off no less than
+ # 7 opcodes. nice!
+ $evalstr .= '
+ ($caught, undef, undef, $rules) = split(\' \', $_, 5);
+ next unless ($caught =~ /^[Y\.]$/ && $rules);
+ ';
+
+ if ($opt_f) {
+ $evalstr .= '
+ next if (!(($caught eq "Y") xor $isspam));
+ ';
+ }
+
+ my $hmapstr = '';
+ if ($isspam) {
+ if ($opt_o) {
+ $hmapstr = '
+ vec ($hmap_spam{$r}, $num_spam, 1) = 1;
+ ';
+ }
+
+ $evalstr .= '
+ $num_spam++;
+ foreach my $r (split(/,/, $rules)) {
$freq_spam{$r}++;
- if ($opt_o) {
- vec ($hmap_spam{$r}, $num_spam, 1) = 1;
- }
+ '.$hmapstr.'
}
+ ';
+ } else {
+ if ($opt_o) {
+ $hmapstr = '
+ vec ($hmap_ham{$r}, $num_ham, 1) = 1;
+ ';
}
- else {
- $num_ham++;
- foreach my $r (split(/,/, $rules)) {
+
+ $evalstr .= '
+ $num_ham++;
+ foreach my $r (split(/,/, $rules)) {
$freq_ham{$r}++;
- if ($opt_o) {
- vec ($hmap_ham{$r}, $num_ham, 1) = 1;
- }
+ '.$hmapstr.'
}
+ ';
+ }
+ $evalstr .= '
}
+ ';
+
+ eval $evalstr;
+
+ if ($@) {
+ die $@;
}
+
close IN;
}
# paranoia: remove zero length rules