diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2010-06-11 09:56:45 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2010-06-11 09:56:45 +0000 |
commit | 39b1b5eab1b7933012dbedee3339064974f6983d (patch) | |
tree | 74f34496507e7ec5c12683a55484aaa04e4d0457 | |
parent | 5326473ef53d4faf3496c2b87de5b9f46aa819e7 (diff) |
add wantarray optimization, just reply 1 as soon as we can when we actually
don't try to build the list.
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PkgCfl.pm | 19 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PkgSpec.pm | 25 |
2 files changed, 33 insertions, 11 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm b/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm index bd6256ff5da..46bc0b98627 100644 --- a/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm +++ b/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PkgCfl.pm,v 1.31 2010/06/04 17:29:53 espie Exp $ +# $OpenBSD: PkgCfl.pm,v 1.32 2010/06/11 09:56:44 espie Exp $ # # Copyright (c) 2003-2005 Marc Espie <espie@openbsd.org> # @@ -47,11 +47,20 @@ sub make_conflict_list sub conflicts_with { my ($self, @pkgnames) = @_; - my @l = (); - for my $cfl (@$self) { - push(@l, $cfl->filter(@pkgnames)); + if (wantarray) { + my @l = (); + for my $cfl (@$self) { + push(@l, $cfl->filter(@pkgnames)); + } + return @l; + } else { + for my $cfl (@$self) { + if ($cfl->filter(@pkgnames)) { + return 1; + } + } + return 0; } - return @l; } sub register($$) diff --git a/usr.sbin/pkg_add/OpenBSD/PkgSpec.pm b/usr.sbin/pkg_add/OpenBSD/PkgSpec.pm index c3fab091d74..a60ce5b46de 100644 --- a/usr.sbin/pkg_add/OpenBSD/PkgSpec.pm +++ b/usr.sbin/pkg_add/OpenBSD/PkgSpec.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PkgSpec.pm,v 1.28 2010/05/10 09:17:55 espie Exp $ +# $OpenBSD: PkgSpec.pm,v 1.29 2010/06/11 09:56:44 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -249,7 +249,11 @@ LOOP1: for my $c (@{$o->{constraints}}) { next LOOP1 unless $c->match($name); } - push(@result, $s); + if (wantarray) { + push(@result, $s); + } else { + return 1; + } } return @result; @@ -296,11 +300,20 @@ sub new sub match_ref { my ($self, $r) = @_; - my @l = (); - for my $subpattern (@$self) { - push(@l, $subpattern->match_ref($r)); + if (wantarray) { + my @l = (); + for my $subpattern (@$self) { + push(@l, $subpattern->match_ref($r)); + } + return @l; + } else { + for my $subpattern (@$self) { + if ($subpattern->match_ref($r)) { + return 1; + } + } + return 0; } - return @l; } sub match_locations |