[perl-extutils-depends: 2/7] simplify uniquify
- From: Torsten Schönfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-extutils-depends: 2/7] simplify uniquify
- Date: Fri, 7 May 2021 19:20:17 +0000 (UTC)
commit 4d93691d22cddf9b5db3808f8abb2d6aa959a232
Author: Ed J <mohawk2 users noreply github com>
Date: Mon Apr 12 15:26:17 2021 +0100
simplify uniquify
lib/ExtUtils/Depends.pm | 11 +----------
t/02_save_load.t | 5 ++++-
2 files changed, 5 insertions(+), 11 deletions(-)
---
diff --git a/lib/ExtUtils/Depends.pm b/lib/ExtUtils/Depends.pm
index 2cfe787..32a6754 100644
--- a/lib/ExtUtils/Depends.pm
+++ b/lib/ExtUtils/Depends.pm
@@ -247,18 +247,9 @@ sub load_deps {
sub uniquify {
my %seen;
- # we use a seen hash, but also keep indices to preserve
- # first-seen order.
- my $i = 0;
- foreach (@_) {
- $seen{$_} = ++$i
- unless exists $seen{$_};
- }
- #warn "stripped ".(@_ - (keys %seen))." redundant elements\n";
- sort { $seen{$a} <=> $seen{$b} } keys %seen;
+ grep !$seen{$_}++, @_;
}
-
sub get_makefile_vars {
my $self = shift;
diff --git a/t/02_save_load.t b/t/02_save_load.t
index 998817f..3df98b2 100644
--- a/t/02_save_load.t
+++ b/t/02_save_load.t
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use Test::More tests => 40;
+use Test::More tests => 41;
use FindBin;
use lib "$FindBin::Bin/lib";
@@ -52,6 +52,9 @@ open my $iffh, '>>', $IFpm or die "write $IFpm: $!";
print $iffh qq{\nwarn "LOADING\\n";\n1;\n};
undef $iffh;
+# test utility function
+is_deeply [ExtUtils::Depends::uniquify(qw(a c b c a b))], [qw(a c b)];
+
# --------------------------------------------------------------------------- #
my %vars = $dep_info->get_makefile_vars;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]