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

Stoiko Ivanov s.ivanov at proxmox.com
Thu Aug 8 11:43:08 CEST 2019


gave both patches a quick spin.
Thanks for the effort - especially the uri hits will make a few users quite happy!

Tested-by: Stoiko Ivanov <s.ivanov at proxmox.com>

On Thu,  8 Aug 2019 10:49:13 +0200
Dominik Csapak <d.csapak at proxmox.com> 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 {




More information about the pmg-devel mailing list