From da18af90f0bebfab92281495b4fc96960da6644d Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Wed, 30 Dec 2009 09:43:35 +0000 Subject: a few small optimizations: - be more specific in what we trim. - iterate over list directly, don't build it. - don't create pattern objects for the most common case (one subpattern) --- usr.sbin/pkg_add/OpenBSD/PkgSpec.pm | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/pkg_add/OpenBSD/PkgSpec.pm b/usr.sbin/pkg_add/OpenBSD/PkgSpec.pm index bed26da9138..997fc93c557 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.22 2009/11/10 14:32:31 espie Exp $ +# $OpenBSD: PkgSpec.pm,v 1.23 2009/12/30 09:43:34 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie # @@ -199,7 +199,7 @@ sub new bless { exactstem => qr{^$stemspec$}, - fuzzystem => qr{^$stemspec-.*$}, + fuzzystem => qr{^$stemspec\-\d.*$}, constraints => $constraints, }, $class; } @@ -207,11 +207,10 @@ sub new sub match_ref { my ($o, $list) = @_; - my @l = grep($o->{fuzzystem}, @$list); my @result = (); # Now, have to extract the version number, and the flavor... LOOP1: - for my $s (@l) { + for my $s (grep($o->{fuzzystem}, @$list)) { my $name = OpenBSD::PackageName->from_string($s); next unless $name->{stem} =~ m/^$o->{exactstem}$/; for my $c (@{$o->{constraints}}) { @@ -226,11 +225,10 @@ LOOP1: sub match_locations { my ($o, $list) = @_; - my @l = grep { $_->name =~ m/$o->{fuzzystem}/} @$list; my $result = []; # Now, have to extract the version number, and the flavor... LOOP2: - for my $s (@l) { + for my $s (grep { $_->name =~ m/$o->{fuzzystem}/} @$list) { my $name = $s->pkgname; next unless $name->{stem} =~ m/^$o->{exactstem}$/; for my $c (@{$o->{constraints}}) { @@ -250,7 +248,11 @@ sub new my ($class, $pattern) = @_; my @l = map { $class->subpattern_class->new($_) } (split /\|/o, $pattern); - bless \@l, $class; + if (@l == 1) { + return $l[0]; + } else { + return bless \@l, $class; + } } sub match_ref -- cgit v1.2.3