[pmg-devel] [PATCH pmg-api 1/2] Who: Domain: improve speed
Dominik Csapak
d.csapak at proxmox.com
Thu Aug 8 10:49:13 CEST 2019
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 at proxmox.com>
---
src/PMG/RuleDB/Domain.pm | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/PMG/RuleDB/Domain.pm b/src/PMG/RuleDB/Domain.pm
index c3530ea..9d60473 100644
--- a/src/PMG/RuleDB/Domain.pm
+++ b/src/PMG/RuleDB/Domain.pm
@@ -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 {
--
2.20.1
More information about the pmg-devel
mailing list