summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2010-06-25 10:13:38 +0000
committerMarc Espie <espie@cvs.openbsd.org>2010-06-25 10:13:38 +0000
commit5313b77025b000a81d7165b51021ee777440b149 (patch)
tree6eb7e2a0dbbfbfc9c8c275c2b4e99518489c9085 /usr.sbin
parentf622e89055d39022331f010ba7ee1b1ad0db2515 (diff)
fix "deduplicate" code.
allow prepend as well as add
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm23
1 files changed, 19 insertions, 4 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm
index 2f81f58ce38..f232d78102b 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageRepositoryList.pm,v 1.22 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: PackageRepositoryList.pm,v 1.23 2010/06/25 10:13:37 espie Exp $
#
# Copyright (c) 2003-2006 Marc Espie <espie@openbsd.org>
#
@@ -23,16 +23,31 @@ package OpenBSD::PackageRepositoryList;
sub new
{
my $class = shift;
- return bless {l => [], c => {}, k => {}}, $class;
+ return bless {l => [], k => {}}, $class;
}
-sub add
+sub filter_new
{
my $self = shift;
+ my @l = ();
for my $r (@_) {
next if $self->{k}{$r};
- push @{$self->{l}}, $r;
+ $self->{k}{$r} = 1;
+ push @l, $r;
}
+ return @l;
+}
+
+sub add
+{
+ my $self = shift;
+ push @{$self->{l}}, $self->filter_new(@_);
+}
+
+sub prepend
+{
+ my $self = shift;
+ unshift @{$self->{l}}, $self->filter_new(@_);
}
sub do_something