Mailing List Archive

svn commit: r438955 - /spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
Author: jm
Date: Thu Aug 31 08:48:54 2006
New Revision: 438955

URL: http://svn.apache.org/viewvc?rev=438955&view=rev
Log:
more speedups: turn off 'tflags multiple' support code if that tflag isn't specified for the rule in question. this shaves off 4.5% of runtime

Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm?rev=438955&r1=438954&r2=438955&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm Thu Aug 31 08:48:54 2006
@@ -1955,26 +1955,49 @@

while (my($rulename, $pat) = each %{$self->{conf}{body_tests}->{$priority}})
{
+ my $sub;
+ if ($self->{conf}->{tflags}->{$rulename} =~ /\bmultiple\b/)
+ {
+ # support multiple matches
+ $loopid++;
+ $sub = '
+ body_'.$loopid.': foreach my $l (@_) {
+ pos $l = 0;
+ '.$self->hash_line_for_rule($rulename).'
+ while ($l =~ '.$pat.'g) {
+ $self->got_hit(q{'.$rulename.'}, "BODY: ", ruletype => "body");
+ '. $self->hit_rule_plugin_code($rulename, "body",
+ "last body_".$loopid) . '
+ }
+ }
+ ';
+ }
+ else {
+ # omitting the "pos" call, "body_loopid" label, use of while()
+ # instead of if() etc., shaves off 8 perl OPs.
+ $sub = '
+ foreach my $l (@_) {
+ '.$self->hash_line_for_rule($rulename).'
+ if ($l =~ '.$pat.') {
+ $self->got_hit(q{'.$rulename.'}, "BODY: ", ruletype => "body");
+ '. $self->hit_rule_plugin_code($rulename, "body", "last") .'
+ }
+ }
+ ';
+ }
+
if ($use_rule_subs) {
$evalstr .= '
if ($scoresptr->{q{'.$rulename.'}}) {
'.$rulename.'_body_test($self,@_);
+ '.$self->ran_rule_plugin_code($rulename, "body").'
}
';
}
else {
- $loopid++;
$evalstr .= '
if ($scoresptr->{q{'.$rulename.'}}) {
- body_'.$loopid.': foreach my $l (@_) {
- pos $l = 0;
- '.$self->hash_line_for_rule($rulename).'
- while ($l =~ '.$pat.'g) {
- $self->got_hit(q{'.$rulename.'}, "BODY: ", ruletype => "body");
- '. $self->hit_rule_plugin_code($rulename, "body",
- "last body_".$loopid) . '
- }
- }
+ '.$sub.'
'.$self->ran_rule_plugin_code($rulename, "body").'
}
';
@@ -1986,17 +2009,7 @@

if ($use_rule_subs) {
$evalstr2 .= '
- sub '.$rulename.'_body_test {
- my $self = shift;
- foreach (@_) {
- pos = 0;
- '.$self->hash_line_for_rule($rulename).'
- while ('.$pat.'g) {
- $self->got_hit(q{'.$rulename.'}, "BODY: ", ruletype => "body");
- '. $self->hit_rule_plugin_code($rulename, "body", "return") . '
- }
- }
- }
+ sub '.$rulename.'_body_test { my $self = shift; '.$sub.' }
';
}
}
@@ -2391,6 +2404,33 @@
my $loopid = 0;

while (my($rulename, $pat) = each %{$self->{conf}{uri_tests}->{$priority}}) {
+ my $sub;
+ if ($self->{conf}->{tflags}->{$rulename} =~ /\bmultiple\b/)
+ {
+ $loopid++;
+ $sub = '
+ uri_'.$loopid.': foreach my $l (@_) {
+ pos $l = 0;
+ '.$self->hash_line_for_rule($rulename).'
+ while ($l =~ '.$pat.'g) {
+ $self->got_hit(q{'.$rulename.'}, "URI: ", ruletype => "uri");
+ '. $self->hit_rule_plugin_code($rulename, "uri",
+ "last uri_".$loopid) . '
+ }
+ }
+ ';
+ } else {
+ $sub = '
+ foreach my $l (@_) {
+ '.$self->hash_line_for_rule($rulename).'
+ if ($l =~ '.$pat.') {
+ $self->got_hit(q{'.$rulename.'}, "URI: ", ruletype => "uri");
+ '. $self->hit_rule_plugin_code($rulename, "uri", "last") .'
+ }
+ }
+ ';
+ }
+
if ($use_rule_subs) {
$evalstr .= '
if ($scoresptr->{q{'.$rulename.'}}) {
@@ -2400,18 +2440,9 @@
';
}
else {
- $loopid++;
$evalstr .= '
if ($scoresptr->{q{'.$rulename.'}}) {
- uri_'.$loopid.': foreach my $l (@_) {
- pos $l = 0;
- '.$self->hash_line_for_rule($rulename).'
- while ($l =~ '.$pat.'g) {
- $self->got_hit(q{'.$rulename.'}, "URI: ", ruletype => "uri");
- '. $self->hit_rule_plugin_code($rulename, "uri",
- "last uri_".$loopid) . '
- }
- }
+ '.$sub.'
'.$self->ran_rule_plugin_code($rulename, "uri").'
}
';
@@ -2423,17 +2454,7 @@

if ($use_rule_subs) {
$evalstr2 .= '
- sub '.$rulename.'_uri_test {
- my $self = shift;
- foreach (@_) {
- pos = 0;
- '.$self->hash_line_for_rule($rulename).'
- while ('.$pat.'g) {
- $self->got_hit(q{'.$rulename.'}, "URI: ", ruletype => "uri");
- '. $self->hit_rule_plugin_code($rulename, "uri", "return") .'
- }
- }
- }
+ sub '.$rulename.'_uri_test { my $self = shift; '.$sub.' }
';
}
}
@@ -2506,6 +2527,35 @@
my $loopid = 0;

while (my($rulename, $pat) = each %{$self->{conf}{rawbody_tests}->{$priority}}) {
+ my $sub;
+ if ($self->{conf}->{tflags}->{$rulename} =~ /\bmultiple\b/)
+ {
+ # support multiple matches
+ $loopid++;
+ $sub = '
+ rawbody_'.$loopid.': foreach my $l (@_) {
+ pos $l = 0;
+ '.$self->hash_line_for_rule($rulename).'
+ while ($l =~ '.$pat.'g) {
+ $self->got_hit(q{'.$rulename.'}, "RAW: ", ruletype => "rawbody");
+ '. $self->hit_rule_plugin_code($rulename, "rawbody",
+ "last rawbody_".$loopid) . '
+ }
+ }
+ ';
+ }
+ else {
+ $sub = '
+ foreach my $l (@_) {
+ '.$self->hash_line_for_rule($rulename).'
+ if ($l =~ '.$pat.') {
+ $self->got_hit(q{'.$rulename.'}, "RAW: ", ruletype => "rawbody");
+ '. $self->hit_rule_plugin_code($rulename, "rawbody", "last") . '
+ }
+ }
+ ';
+ }
+
if ($use_rule_subs) {
$evalstr .= '
if ($scoresptr->{q{'.$rulename.'}}) {
@@ -2515,18 +2565,9 @@
';
}
else {
- $loopid++;
$evalstr .= '
if ($scoresptr->{q{'.$rulename.'}}) {
- rawbody_'.$loopid.': foreach my $l (@_) {
- pos $l = 0;
- '.$self->hash_line_for_rule($rulename).'
- while ($l =~ '.$pat.'g) {
- $self->got_hit(q{'.$rulename.'}, "RAW: ", ruletype => "rawbody");
- '. $self->hit_rule_plugin_code($rulename, "rawbody",
- "last rawbody_".$loopid) . '
- }
- }
+ '.$sub.'
'.$self->ran_rule_plugin_code($rulename, "rawbody").'
}
';
@@ -2538,17 +2579,7 @@

if ($use_rule_subs) {
$evalstr2 .= '
- sub '.$rulename.'_rawbody_test {
- my $self = shift;
- foreach (@_) {
- pos = 0;
- '.$self->hash_line_for_rule($rulename).'
- while ('.$pat.'g) {
- $self->got_hit(q{'.$rulename.'}, "RAW: ", ruletype => "rawbody");
- '. $self->hit_rule_plugin_code($rulename, "rawbody", "return") . '
- }
- }
- }
+ sub '.$rulename.'_rawbody_test { my $self = shift; '.$sub.' }
';
}
}