]> git.saurik.com Git - apt.git/commitdiff
Readd the FindPkg() method implementation used in the singleArch days to
authorDavid Kalnischkies <kalnischkies@gmail.com>
Thu, 18 Mar 2010 17:51:14 +0000 (18:51 +0100)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Thu, 18 Mar 2010 17:51:14 +0000 (18:51 +0100)
use it as a fallback if multiarch is not enabled. The effect is barly
noticeable but SingleArch is the realworld scenario.

apt-pkg/pkgcache.cc
apt-pkg/pkgcache.h

index 24d9e032994c3a40230ad6a5c8e84793cd4bf3e0..fe8757ded3af111c46406e17d52968a92185df7a 100644 (file)
@@ -108,6 +108,7 @@ bool pkgCache::Header::CheckSizes(Header &Against) const
 /* */
 pkgCache::pkgCache(MMap *Map, bool DoMap) : Map(*Map)
 {
+   MultiArchEnabled = APT::Configuration::getArchitectures().size() > 1;
    if (DoMap == true)
       ReMap();
 }
@@ -178,11 +179,31 @@ unsigned long pkgCache::sHash(const char *Str) const
    return Hash % _count(HeaderP->PkgHashTable);
 }
 
+                                                                       /*}}}*/
+// Cache::SingleArchFindPkg - Locate a package by name                 /*{{{*/
+// ---------------------------------------------------------------------
+/* Returns 0 on error, pointer to the package otherwise
+   The multiArch enabled methods will fallback to this one as it is (a bit)
+   faster for single arch environments and realworld is mostly singlearch… */
+pkgCache::PkgIterator pkgCache::SingleArchFindPkg(const string &Name)
+{
+   // Look at the hash bucket
+   Package *Pkg = PkgP + HeaderP->PkgHashTable[Hash(Name)];
+   for (; Pkg != PkgP; Pkg = PkgP + Pkg->NextPackage)
+   {
+      if (Pkg->Name != 0 && StrP[Pkg->Name] == Name[0] &&
+          stringcasecmp(Name,StrP + Pkg->Name) == 0)
+         return PkgIterator(*this,Pkg);
+   }
+   return PkgIterator(*this,0);
+}
                                                                        /*}}}*/
 // Cache::FindPkg - Locate a package by name                           /*{{{*/
 // ---------------------------------------------------------------------
 /* Returns 0 on error, pointer to the package otherwise */
 pkgCache::PkgIterator pkgCache::FindPkg(const string &Name) {
+       if (MultiArchCache() == false)
+               return SingleArchFindPkg(Name);
        size_t const found = Name.find(':');
        if (found == string::npos)
                return FindPkg(Name, "native");
@@ -195,7 +216,14 @@ pkgCache::PkgIterator pkgCache::FindPkg(const string &Name) {
 // Cache::FindPkg - Locate a package by name                           /*{{{*/
 // ---------------------------------------------------------------------
 /* Returns 0 on error, pointer to the package otherwise */
-pkgCache::PkgIterator pkgCache::FindPkg(const string &Name, string Arch) {
+pkgCache::PkgIterator pkgCache::FindPkg(const string &Name, string const &Arch) {
+       if (MultiArchCache() == false) {
+               if (Arch == "native" || Arch == "all" ||
+                   Arch == _config->Find("APT::Architecture"))
+                       return SingleArchFindPkg(Name);
+               else
+                       return PkgIterator(*this,0);
+       }
        /* We make a detour via the GrpIterator here as
           on a multi-arch environment a group is easier to
           find than a package (less entries in the buckets) */
index 012caac76c5a0e5cdd14f7077cd365ff546b0ec3..577eebad9c58474c33560f8ded120f57f7389215 100644 (file)
@@ -126,7 +126,7 @@ class pkgCache                                                              /*{{{*/
    // Accessors
    GrpIterator FindGrp(const string &Name);
    PkgIterator FindPkg(const string &Name);
-   PkgIterator FindPkg(const string &Name, string Arch);
+   PkgIterator FindPkg(const string &Name, const string &Arch);
 
    Header &Head() {return *HeaderP;};
    inline GrpIterator GrpBegin();
@@ -136,6 +136,8 @@ class pkgCache                                                              /*{{{*/
    inline PkgFileIterator FileBegin();
    inline PkgFileIterator FileEnd();
 
+   inline bool MultiArchCache() const { return MultiArchEnabled; };
+
    // Make me a function
    pkgVersioningSystem *VS;
    
@@ -146,6 +148,10 @@ class pkgCache                                                             /*{{{*/
    
    pkgCache(MMap *Map,bool DoMap = true);
    virtual ~pkgCache() {};
+
+private:
+   bool MultiArchEnabled;
+   PkgIterator SingleArchFindPkg(const string &Name);
 };
                                                                        /*}}}*/
 // Header structure                                                    /*{{{*/