Skip to content

Commit

Permalink
update ends_with with a faster version
Browse files Browse the repository at this point in the history
  • Loading branch information
jrouzierinverse committed Oct 3, 2024
1 parent 61bf6c1 commit 4ab1f69
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/pf/util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1887,10 +1887,6 @@ sub extract {
return $default;
}

sub ends_with {
return $_[1] eq substr($_[0], -length($_[1]));
}

sub split_pem {
my ($s) = @_;
my @parts;
Expand Down Expand Up @@ -1981,6 +1977,10 @@ sub starts_with {
return rindex($_[0], $_[1], 0) == 0;
}

sub ends_with {
return index($_[0], $_[1], -length($_[1])) != -1;
}

=back
=head1 AUTHOR
Expand Down
10 changes: 9 additions & 1 deletion t/util.t
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ use Test::More;
use Test::NoWarnings;

BEGIN {
plan tests => 47 +
plan tests => 55 +
((scalar @NODE_ID_TESTS) * 3) +
scalar @STRIP_FILENAME_FROM_EXCEPTIONS_TESTS +
scalar @INVALID_DATES +
Expand Down Expand Up @@ -505,7 +505,15 @@ for my $test (@MAC2DEC) {

{
ok(starts_with("dog", "do"), "starts_with");
ok(starts_with("dog", "dog"), "starts_with");
ok(starts_with("dog", ""), "starts_with");
ok(!starts_with("cat", "do"), "starts_with");
ok(!starts_with("cat", "catt"), "starts_with");
ok(ends_with("dog", "og"), "ends_with");
ok(ends_with("dog", "dog"), "ends_with");
ok(ends_with("dog", ""), "ends_with");
ok(!ends_with("cat", "og"), "ends_with");
ok(!ends_with("cat", "catt"), "ends_with");
}

=head1 AUTHOR
Expand Down

0 comments on commit 4ab1f69

Please sign in to comment.