-# === everything from here is adapted from debbugs, and should probably be merged
-# === back at some point
-
-my %_binarytosource;
-my %_binarytosourcecache = ();
-sub binarytosource {
- my ($binname, $binver, $binarch) = @_;
-
- # TODO: This gets hit a lot, especially from buggyversion() - probably
- # need an extra cache for speed here.
-
- if (tied %_binarytosource or
- tie %_binarytosource, 'MLDBM',
- $Debbugs::Packages::gBinarySourceMap, O_RDONLY) {
- if (!exists($_binarytosourcecache{$binname})) {
- $_binarytosourcecache{$binname} = \%{ $_binarytosource{$binname} };
- }
-
- if (defined $_binarytosourcecache{$binname} and
- exists $_binarytosourcecache{$binname}{$binver}) {
- if (defined $binarch) {
- my $src = $_binarytosourcecache{$binname}{$binver}{$binarch};
- return () unless defined $src; # not on this arch
- # Copy the data to avoid tiedness problems.
- return [@$src];
- } else {
- # Get (srcname, srcver) pairs for all architectures and
- # remove any duplicates. This involves some slightly tricky
- # multidimensional hashing; sorry. Fortunately there'll
- # usually only be one pair returned.
- my %uniq;
- for my $ar (keys %{$_binarytosourcecache{$binname}{$binver}}) {
- my $src = $_binarytosourcecache{$binname}{$binver}{$ar};
- next unless defined $src;
- $uniq{$src->[0]}{$src->[1]} = 1;
- }
- my @uniq;
- for my $sn (sort keys %uniq) {
- push @uniq, [$sn, $_] for sort keys %{$uniq{$sn}};
- }
- return @uniq;
- }
- }
- }
-
- # No $gBinarySourceMap, or it didn't have an entry for this name and
- # version.
- return ();
-}