From 196f4f117b4e43f12ee091f9c21e2ce138b289e9 Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Thu, 11 Nov 2004 15:32:29 +0000 Subject: 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. --- usr.sbin/pkg_add/OpenBSD/PackingList.pm | 39 ++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'usr.sbin') 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 # @@ -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; -- cgit v1.2.3