pkgcache.h: tweak FindPkg routines

This commit is contained in:
Alexey Tourbin 2011-01-27 06:21:06 +03:00
parent 8a871f0b52
commit a816216e64
2 changed files with 17 additions and 18 deletions

View File

@ -25,6 +25,7 @@
#pragma implementation "apt-pkg/cacheiterators.h" #pragma implementation "apt-pkg/cacheiterators.h"
#endif #endif
#define PKGCACHE_FINDPKG_ABI
#include <apt-pkg/pkgcache.h> #include <apt-pkg/pkgcache.h>
#include <apt-pkg/version.h> #include <apt-pkg/version.h>
#include <apt-pkg/error.h> #include <apt-pkg/error.h>
@ -185,22 +186,16 @@ unsigned long pkgCache::sHash(const char *Str) const
// Cache::FindPkg - Locate a package by name /*{{{*/ // Cache::FindPkg - Locate a package by name /*{{{*/
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/* Returns 0 on error, pointer to the package otherwise */ /* Returns 0 on error, pointer to the package otherwise */
pkgCache::PkgIterator pkgCache::FindPkg(const string &Name)
{
return PkgIterator(*this,FindPackage(Name.c_str()));
}
#ifdef PKGCACHE_FINDPKG_ABI
pkgCache::PkgIterator pkgCache::FindPkg(string Name) pkgCache::PkgIterator pkgCache::FindPkg(string Name)
{ {
// Look at the hash bucket return PkgIterator(*this,FindPackage(Name.c_str()));
Package *Pkg = PkgP + HeaderP->HashTable[Hash(Name)];
const char *name = Name.c_str(); // CNC:2003-02-17
for (; Pkg != PkgP; Pkg = PkgP + Pkg->NextPackage)
{
// CNC:2003-02-17 - We use case sensitive package names. Also,
// store Pkg->Name in a temporary variable.
map_ptrloc PkgName = Pkg->Name;
if (PkgName != 0 && StrP[PkgName] == name[0] &&
strcmp(name,StrP + PkgName) == 0)
return PkgIterator(*this,Pkg);
}
return PkgIterator(*this,0);
} }
#endif
/*}}}*/ /*}}}*/
// CNC:2003-02-17 - A slightly changed FindPkg(), hacked for performance. // CNC:2003-02-17 - A slightly changed FindPkg(), hacked for performance.
@ -213,12 +208,13 @@ pkgCache::Package *pkgCache::FindPackage(const char *Name)
Package *Pkg = PkgP + HeaderP->HashTable[Hash(Name)]; Package *Pkg = PkgP + HeaderP->HashTable[Hash(Name)];
for (; Pkg != PkgP; Pkg = PkgP + Pkg->NextPackage) for (; Pkg != PkgP; Pkg = PkgP + Pkg->NextPackage)
{ {
// CNC:2003-02-17 - We use case sensitive package names. Also, // CNC:2003-02-17 - We use case sensitive package names.
// store Pkg->Name in a temporary variable.
map_ptrloc PkgName = Pkg->Name; map_ptrloc PkgName = Pkg->Name;
if (PkgName != 0 && StrP[PkgName] == Name[0] && if (PkgName != 0) {
strcmp(Name,StrP + PkgName) == 0) const char *S = StrP + PkgName;
return Pkg; if (*S == *Name && strcmp(S, Name) == 0)
return Pkg;
}
} }
return NULL; return NULL;
} }

View File

@ -138,7 +138,10 @@ class pkgCache
const char *Priority(unsigned char Priority); const char *Priority(unsigned char Priority);
// Accessors // Accessors
PkgIterator FindPkg(const string &Name);
#ifdef PKGCACHE_FINDPKG_ABI
PkgIterator FindPkg(string Name); PkgIterator FindPkg(string Name);
#endif
// CNC:2003-02-17 - A slightly changed FindPkg(), hacked for performance. // CNC:2003-02-17 - A slightly changed FindPkg(), hacked for performance.
Package *FindPackage(const char *Name); Package *FindPackage(const char *Name);
Header &Head() {return *HeaderP;}; Header &Head() {return *HeaderP;};