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 520e67ed67)
mr7.5.5
Guillem Jover 6 years ago committed by Rene Krenn
parent 849c02becd
commit defd88771b

@ -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;

Loading…
Cancel
Save