]> git.proxmox.com Git - pmg-api.git/commitdiff
Who: Domain: improve speed
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 8 Aug 2019 08:49:13 +0000 (10:49 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 8 Aug 2019 11:09:44 +0000 (13:09 +0200)
a split is about 20% faster than doing a regex match here, for
a typical email address and domain
(benchmarked with Benchmark::cmpthese)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Stoiko Ivanov <s.ivanov@proxmox.com>
src/PMG/RuleDB/Domain.pm

index c3530eacbdb71f7be0d430e22f713f01689131bd..9d604731157b48ee802e45f946cba39e40bb5aff 100644 (file)
@@ -31,11 +31,12 @@ sub new {
 sub who_match {
     my ($self, $addr) = @_;
 
-    $addr =~ m/^.+@(.+)$/;
+    my @parts = split('@', $addr);
 
-    return undef if !defined($1);
+    return undef if scalar(@parts) < 2;
 
-    return (lc ($1) eq lc ($self->address));
+    my $domain = $parts[-1]; # last element
+    return lc $domain eq lc $self->{address};
 }
 
 sub short_desc {