summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2004-11-11 15:32:29 +0000
committerMarc Espie <espie@cvs.openbsd.org>2004-11-11 15:32:29 +0000
commit196f4f117b4e43f12ee091f9c21e2ce138b289e9 (patch)
treee8f26504f32ba4acdfc6606fa34b7018efe648d6
parent3fa81e58a488fd2fedb4d90be6a9797a8dee7439 (diff)
cache packing-lists, so that we don't read them again and again.
big win as soon as pkg_add -r updates two or three packages with lots of dependencies.
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackingList.pm39
1 files changed, 34 insertions, 5 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingList.pm b/usr.sbin/pkg_add/OpenBSD/PackingList.pm
index a1b963c920e..966456e1f32 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackingList.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackingList.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackingList.pm,v 1.33 2004/11/11 11:16:40 espie Exp $
+# $OpenBSD: PackingList.pm,v 1.34 2004/11/11 15:32:28 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -299,14 +299,32 @@ sub visit
}
}
+my $plist_cache = {};
+
sub from_installation
{
- my ($o, $name, @args) = @_;
+ my ($o, $pkgname, $code) = @_;
require OpenBSD::PackageInfo;
- return $o->fromfile(OpenBSD::PackageInfo::installed_contents($name),
- @args);
+ if (defined $plist_cache->{\&defaultCode}->{$pkgname}) {
+ return $plist_cache->{\&defaultCode}->{$pkgname};
+ }
+ $code = \&defaultCode if !defined $code;
+
+ if (!defined $plist_cache->{$code}->{$pkgname}) {
+ my $plist =
+ $o->fromfile(OpenBSD::PackageInfo::installed_contents($pkgname),
+ $code);
+ if (defined $plist) {
+ $plist->{code} = $code;
+ $plist_cache->{$code}->{$pkgname} = $plist;
+ return $plist;
+ } else {
+ return undef;
+ }
+ }
+ return $plist_cache->{$code}->{$pkgname};
}
sub to_installation
@@ -315,7 +333,18 @@ sub to_installation
require OpenBSD::PackageInfo;
- $self->tofile(OpenBSD::PackageInfo::installed_contents($self->pkgname()));
+ my $pkgname = $self->pkgname();
+
+ $self->tofile(OpenBSD::PackageInfo::installed_contents($pkgname));
+ $plist_cache->{\&defaultCode}->{$pkgname} = $self;
+}
+
+
+sub forget
+{
+ my ($self) = @_;
+
+ delete $plist_cache->{$self->{code}}->{$self->pkgname()};
}
1;