You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by he...@apache.org on 2019/06/15 11:48:05 UTC

svn commit: r1861374 - /spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm

Author: hege
Date: Sat Jun 15 11:48:05 2019
New Revision: 1861374

URL: http://svn.apache.org/viewvc?rev=1861374&view=rev
Log:
Move expand_ruleglob function to global, save few cpu cycles

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm?rev=1861374&r1=1861373&r2=1861374&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm Sat Jun 15 11:48:05 2019
@@ -526,6 +526,30 @@ sub add_temporary_method {
 
 ###########################################################################
 
+# Returns all rulenames matching glob (FOO_*)
+sub expand_ruleglob {
+  my ($self, $ruleglob, $pms, $conf) = @_;
+  my $expanded;
+  if (exists $pms->{ruleglob_cache}{$ruleglob}) {
+    $expanded = $pms->{ruleglob_cache}{$ruleglob};
+  } else {
+    my $reglob = $ruleglob;
+    $reglob =~ s/\?/./g;
+    $reglob =~ s/\*/.*?/g;
+    # Glob rules, but do not match ourselves..
+    my @rules = grep {/^${reglob}$/ && $_ ne $rulename} keys %{$conf->{scores}};
+    if (@rules) {
+      $expanded = join('+', sort @rules);
+    } else {
+      $expanded = '0';
+    }
+  }
+  my $logstr = $expanded eq '0' ? 'no matches' : $expanded;
+  dbg("rules: meta $rulename rules_matching($ruleglob) expanded: $logstr");
+  $pms->{ruleglob_cache}{$ruleglob} = $expanded;
+  return " ($expanded) ";
+};
+
 sub do_meta_tests {
   my ($self, $pms, $priority) = @_;
   my (%rule_deps, %meta, $rulename);
@@ -539,30 +563,8 @@ sub do_meta_tests {
   {
     my ($self, $pms, $conf, $rulename, $rule, %opts) = @_;
 
-    # Expand rules_matching() before lexing
-    my $expand_ruleglob = sub {
-      my ($ruleglob) = @_;
-      my $expanded;
-      if (exists $pms->{ruleglob_cache}{$ruleglob}) {
-        $expanded = $pms->{ruleglob_cache}{$ruleglob};
-      } else {
-        my $reglob = $ruleglob;
-        $reglob =~ s/\?/./g;
-        $reglob =~ s/\*/.*?/g;
-        # Glob rules, but do not match ourselves..
-        my @rules = grep {/^${reglob}$/ && $_ ne $rulename} keys %{$conf->{scores}};
-        if (@rules) {
-          $expanded = join('+', sort @rules);
-        } else {
-          $expanded = '0';
-        }
-      }
-      my $logstr = $expanded eq '0' ? 'no matches' : $expanded;
-      dbg("rules: meta $rulename rules_matching($ruleglob) expanded: $logstr");
-      $pms->{ruleglob_cache}{$ruleglob} = $expanded;
-      return " ($expanded) ";
-    };
-    $rule =~ s/${META_RULES_MATCHING_RE}/$expand_ruleglob->($1)/ge;
+    # Expand meta rules_matching() before lexing
+    $rule =~ s/${META_RULES_MATCHING_RE}/$self->expand_ruleglob($1,$pms,$conf)/ge;
 
     # Lex the rule into tokens using a rather simple RE method ...
     my @tokens = ($rule =~ /$ARITH_EXPRESSION_LEXER/og);