[pmg-devel] applied: [PATCH pmg-api 1/2] Who: Domain: improve speed

Fabian Grünbichler f.gruenbichler at proxmox.com
Thu Aug 8 13:12:31 CEST 2019


On August 8, 2019 10:49 am, Dominik Csapak wrote:
> 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
> 
> 
> _______________________________________________
> pmg-devel mailing list
> pmg-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel
> 
> 



More information about the pmg-devel mailing list