From defd88771b206d6e273d9dbd95e653248611d951 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Fri, 8 Nov 2019 23:23:53 +0100 Subject: [PATCH] TT#69200 Rewrite setcontains() to use a hash instead of contains() This reduces the complexity of the algorithm, at the expense of more code, which makes it faster: Rate old new old 57803/s -- -23% new 74906/s 30% -- Change-Id: Ic230cddceb269e4c452f3713e75be16569908458 (cherry picked from commit 520e67ed67f8e86807a451b87d8509b0435d1ef1) --- lib/NGCP/BulkProcessor/Array.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/NGCP/BulkProcessor/Array.pm b/lib/NGCP/BulkProcessor/Array.pm index a0c6f6d..cf43515 100644 --- a/lib/NGCP/BulkProcessor/Array.pm +++ b/lib/NGCP/BulkProcessor/Array.pm @@ -161,8 +161,18 @@ sub setcontains { my $ubound1 = _array_last($array_ptr1) // -1; # every element of array1 must be existent in array2: - foreach my $i (0 .. $ubound1) { - return 0 if not contains($array_ptr1->[$i], $array_ptr2, $case_insensitive); + if ($case_insensitive) { + my %set2 = map { lc() => 1 } @{$array_ptr2}; + + foreach my $i (0 .. $ubound1) { + return 0 if not exists $set2{lc $array_ptr1->[$i]}; + } + } else { + my %set2 = map { $_ => 1 } @{$array_ptr2}; + + foreach my $i (0 .. $ubound1) { + return 0 if not exists $set2{$array_ptr1->[$i]}; + } } return 1;