From 69c2ecbdc937e3c73fe67d3c9bce12a80d3ec7ec Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 10 Mar 2013 12:24:13 +0100 Subject: various simple changes to fix cppcheck warnings --- apt-pkg/acquire-item.cc | 4 ++-- apt-pkg/aptconfiguration.cc | 2 +- apt-pkg/cachefilter.cc | 3 +-- apt-pkg/contrib/configuration.cc | 2 +- apt-pkg/contrib/fileutl.cc | 10 +++++----- apt-pkg/contrib/netrc.cc | 8 +++----- apt-pkg/contrib/strutl.cc | 8 ++++---- apt-pkg/deb/dpkgpm.cc | 17 +++++++---------- apt-pkg/indexcopy.cc | 6 ++---- apt-pkg/orderlist.cc | 4 +++- apt-pkg/pkgcache.cc | 18 +++++++++--------- apt-pkg/srcrecords.cc | 11 +++++------ apt-pkg/vendor.cc | 2 +- apt-pkg/versionmatch.cc | 2 +- 14 files changed, 45 insertions(+), 52 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index a71886a8..6ad10e26 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -560,7 +560,7 @@ pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire *Owner, Desc.Owner = this; Desc.ShortDesc = ShortDesc; - if(available_patches.size() == 0) + if(available_patches.empty() == true) { // we are done (yeah!) Finish(true); @@ -1643,7 +1643,7 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources, assumption here that all the available sources for this version share the same extension.. */ // Skip not source sources, they do not have file fields. - for (; Vf.end() == false; Vf++) + for (; Vf.end() == false; ++Vf) { if ((Vf.File()->Flags & pkgCache::Flag::NotSource) != 0) continue; diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index 65377568..37c84658 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -401,8 +401,8 @@ std::vector const Configuration::getArchitectures(bool const &Cache close(external[1]); FILE *dpkg = fdopen(external[0], "r"); - char buf[1024]; if(dpkg != NULL) { + char buf[1024]; while (fgets(buf, sizeof(buf), dpkg) != NULL) { char* arch = strtok(buf, " "); while (arch != NULL) { diff --git a/apt-pkg/cachefilter.cc b/apt-pkg/cachefilter.cc index 58cc812b..64cde41d 100644 --- a/apt-pkg/cachefilter.cc +++ b/apt-pkg/cachefilter.cc @@ -71,8 +71,7 @@ static std::string CompleteArch(std::string const &arch) { } /*}}}*/ PackageArchitectureMatchesSpecification::PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern) :/*{{{*/ - literal(pattern), isPattern(isPattern), d(NULL) { - complete = CompleteArch(pattern); + literal(pattern), complete(CompleteArch(pattern)), isPattern(isPattern), d(NULL) { } /*}}}*/ bool PackageArchitectureMatchesSpecification::operator() (char const * const &arch) {/*{{{*/ diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index 4de17e3e..808a708a 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -958,7 +958,7 @@ Configuration::MatchAgainstConfig::MatchAgainstConfig(char const * Config) continue; } } - if (strings.size() == 0) + if (strings.empty() == true) patterns.push_back(NULL); } /*}}}*/ diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 90e49cbf..f18e1700 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -387,7 +387,7 @@ std::vector GetListOfFilesInDir(string const &Dir, std::vector c std::vector List; - if (DirectoryExists(Dir.c_str()) == false) + if (DirectoryExists(Dir) == false) { _error->Error(_("List of files can't be created as '%s' is not a directory"), Dir.c_str()); return List; @@ -413,14 +413,14 @@ std::vector GetListOfFilesInDir(string const &Dir, std::vector c if (Ent->d_type != DT_REG) #endif { - if (RealFileExists(File.c_str()) == false) + if (RealFileExists(File) == false) { // do not show ignoration warnings for directories if ( #ifdef _DIRENT_HAVE_D_TYPE Ent->d_type == DT_DIR || #endif - DirectoryExists(File.c_str()) == true) + DirectoryExists(File) == true) continue; if (SilentIgnore.Match(Ent->d_name) == false) _error->Notice(_("Ignoring '%s' in directory '%s' as it is not a regular file"), Ent->d_name, Dir.c_str()); @@ -501,7 +501,7 @@ std::vector GetListOfFilesInDir(string const &Dir, bool SortList) std::vector List; - if (DirectoryExists(Dir.c_str()) == false) + if (DirectoryExists(Dir) == false) { _error->Error(_("List of files can't be created as '%s' is not a directory"), Dir.c_str()); return List; @@ -526,7 +526,7 @@ std::vector GetListOfFilesInDir(string const &Dir, bool SortList) if (Ent->d_type != DT_REG) #endif { - if (RealFileExists(File.c_str()) == false) + if (RealFileExists(File) == false) { if (Debug == true) std::clog << "Bad file: " << Ent->d_name << " → it is not a real file" << std::endl; diff --git a/apt-pkg/contrib/netrc.cc b/apt-pkg/contrib/netrc.cc index 0a902f12..de95aa4a 100644 --- a/apt-pkg/contrib/netrc.cc +++ b/apt-pkg/contrib/netrc.cc @@ -50,14 +50,10 @@ static int parsenetrc_string (char *host, std::string &login, std::string &passw FILE *file; int retcode = 1; int specific_login = (login.empty() == false); - char *home = NULL; bool netrc_alloc = false; - int state_our_login = false; /* With specific_login, - found *our* login name */ - if (!netrcfile) { - home = getenv ("HOME"); /* portable environment reader */ + char const * home = getenv ("HOME"); /* portable environment reader */ if (!home) { struct passwd *pw; @@ -86,6 +82,8 @@ static int parsenetrc_string (char *host, std::string &login, std::string &passw int state = NOTHING; char state_login = 0; /* Found a login keyword */ char state_password = 0; /* Found a password keyword */ + int state_our_login = false; /* With specific_login, + found *our* login name */ while (!done && getline(&netrcbuffer, &netrcbuffer_size, file) != -1) { tok = strtok_r (netrcbuffer, " \t\n", &tok_buf); diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index ca096d73..f643db45 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1246,7 +1246,7 @@ string StripEpoch(const string &VerStr) return VerStr; return VerStr.substr(i+1); } - + /*}}}*/ // tolower_ascii - tolower() function that ignores the locale /*{{{*/ // --------------------------------------------------------------------- /* This little function is the most called method we have and tries @@ -1284,14 +1284,14 @@ bool CheckDomainList(const string &Host,const string &List) return false; } /*}}}*/ -// DeEscapeString - unescape (\0XX and \xXX) from a string /*{{{*/ +// DeEscapeString - unescape (\0XX and \xXX) from a string /*{{{*/ // --------------------------------------------------------------------- /* */ string DeEscapeString(const string &input) { char tmp[3]; - string::const_iterator it, escape_start; - string output, octal, hex; + string::const_iterator it; + string output; for (it = input.begin(); it != input.end(); ++it) { // just copy non-escape chars diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 6cb8bc6b..3bc31dc3 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -147,11 +147,11 @@ static pkgCache::VerIterator FindNowVersion(const pkgCache::PkgIterator &Pkg) { pkgCache::VerIterator Ver; - for (Ver = Pkg.VersionList(); Ver.end() == false; Ver++) + for (Ver = Pkg.VersionList(); Ver.end() == false; ++Ver) { pkgCache::VerFileIterator Vf = Ver.FileList(); pkgCache::PkgFileIterator F = Vf.File(); - for (F = Vf.File(); F.end() == false; F++) + for (F = Vf.File(); F.end() == false; ++F) { if (F && F.Archive()) { @@ -1585,12 +1585,12 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg) if (!logfile_name.empty()) { FILE *log = NULL; - char buf[1024]; fprintf(report, "DpkgTerminalLog:\n"); log = fopen(logfile_name.c_str(),"r"); if(log != NULL) { + char buf[1024]; while( fgets(buf, sizeof(buf), log) != NULL) fprintf(report, " %s", buf); fclose(log); @@ -1609,13 +1609,11 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg) // attach dmesg log (to learn about segfaults) if (FileExists("/bin/dmesg")) { - FILE *log = NULL; - char buf[1024]; - fprintf(report, "Dmesg:\n"); - log = popen("/bin/dmesg","r"); + FILE *log = popen("/bin/dmesg","r"); if(log != NULL) { + char buf[1024]; while( fgets(buf, sizeof(buf), log) != NULL) fprintf(report, " %s", buf); pclose(log); @@ -1625,13 +1623,12 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg) // attach df -l log (to learn about filesystem status) if (FileExists("/bin/df")) { - FILE *log = NULL; - char buf[1024]; fprintf(report, "Df:\n"); - log = popen("/bin/df -l","r"); + FILE *log = popen("/bin/df -l","r"); if(log != NULL) { + char buf[1024]; while( fgets(buf, sizeof(buf), log) != NULL) fprintf(report, " %s", buf); pclose(log); diff --git a/apt-pkg/indexcopy.cc b/apt-pkg/indexcopy.cc index aa1f01a4..6e35fc40 100644 --- a/apt-pkg/indexcopy.cc +++ b/apt-pkg/indexcopy.cc @@ -141,7 +141,6 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector &List, File = OrigPath + ChopDirs(File,Chop); // See if the file exists - bool Mangled = false; if (NoStat == false || Hits < 10) { // Attempt to fix broken structure @@ -164,6 +163,7 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector &List, if (stat(string(CDROM + Prefix + File).c_str(),&Buf) != 0 || Buf.st_size == 0) { + bool Mangled = false; // Attempt to fix busted symlink support for one instance string OrigFile = File; string::size_type Start = File.find("binary-"); @@ -799,9 +799,7 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name, /*{{{*/ unsigned int WrongSize = 0; unsigned int Packages = 0; for (vector::iterator I = List.begin(); I != List.end(); ++I) - { - string OrigPath = string(*I,CDROM.length()); - + { // Open the package file FileFd Pkg(*I, FileFd::ReadOnly, FileFd::Auto); off_t const FileSize = Pkg.Size(); diff --git a/apt-pkg/orderlist.cc b/apt-pkg/orderlist.cc index 3a179b2a..80d8fd49 100644 --- a/apt-pkg/orderlist.cc +++ b/apt-pkg/orderlist.cc @@ -331,9 +331,11 @@ int pkgOrderList::Score(PkgIterator Pkg) } // Important Required Standard Optional Extra - signed short PrioMap[] = {0,5,4,3,1,0}; if (Cache[Pkg].InstVerIter(Cache)->Priority <= 5) + { + signed short PrioMap[] = {0,5,4,3,1,0}; Score += PrioMap[Cache[Pkg].InstVerIter(Cache)->Priority]; + } return Score; } /*}}}*/ diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 1de33ff9..1378876f 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -279,22 +279,22 @@ pkgCache::GrpIterator pkgCache::FindGrp(const string &Name) { type in the weird debian style.. */ const char *pkgCache::CompTypeDeb(unsigned char Comp) { - const char *Ops[] = {"","<=",">=","<<",">>","=","!="}; - if ((unsigned)(Comp & 0xF) < 7) - return Ops[Comp & 0xF]; - return ""; + const char * const Ops[] = {"","<=",">=","<<",">>","=","!="}; + if (unlikely((unsigned)(Comp & 0xF) >= sizeof(Ops)/sizeof(Ops[0]))) + return ""; + return Ops[Comp & 0xF]; } /*}}}*/ // Cache::CompType - Return a string describing the compare type /*{{{*/ // --------------------------------------------------------------------- -/* This returns a string representation of the dependency compare +/* This returns a string representation of the dependency compare type */ const char *pkgCache::CompType(unsigned char Comp) { - const char *Ops[] = {"","<=",">=","<",">","=","!="}; - if ((unsigned)(Comp & 0xF) < 7) - return Ops[Comp & 0xF]; - return ""; + const char * const Ops[] = {"","<=",">=","<",">","=","!="}; + if (unlikely((unsigned)(Comp & 0xF) >= sizeof(Ops)/sizeof(Ops[0]))) + return ""; + return Ops[Comp & 0xF]; } /*}}}*/ // Cache::DepType - Return a string describing the dep type /*{{{*/ diff --git a/apt-pkg/srcrecords.cc b/apt-pkg/srcrecords.cc index d63d2c42..29755995 100644 --- a/apt-pkg/srcrecords.cc +++ b/apt-pkg/srcrecords.cc @@ -42,7 +42,7 @@ pkgSrcRecords::pkgSrcRecords(pkgSourceList &List) : d(NULL), Files(0), Current(0 } // Doesn't work without any source index files - if (Files.size() == 0) + if (Files.empty() == true) { _error->Error(_("You must put some 'source' URIs" " in your sources.list")); @@ -121,14 +121,13 @@ pkgSrcRecords::Parser *pkgSrcRecords::Find(const char *Package,bool const &SrcOn /* */ const char *pkgSrcRecords::Parser::BuildDepType(unsigned char const &Type) { - const char *fields[] = {"Build-Depends", - "Build-Depends-Indep", + const char *fields[] = {"Build-Depends", + "Build-Depends-Indep", "Build-Conflicts", "Build-Conflicts-Indep"}; - if (Type < 4) - return fields[Type]; - else + if (unlikely(Type >= sizeof(fields)/sizeof(fields[0]))) return ""; + return fields[Type]; } /*}}}*/ diff --git a/apt-pkg/vendor.cc b/apt-pkg/vendor.cc index 36fc2595..fc03ec84 100644 --- a/apt-pkg/vendor.cc +++ b/apt-pkg/vendor.cc @@ -12,7 +12,7 @@ Vendor::Vendor(std::string VendorID, this->VendorID = VendorID; this->Origin = Origin; for (std::vector::iterator I = FingerprintList->begin(); - I != FingerprintList->end(); I++) + I != FingerprintList->end(); ++I) { if (_config->FindB("Debug::Vendor", false)) std::cerr << "Vendor \"" << VendorID << "\": Mapping \"" diff --git a/apt-pkg/versionmatch.cc b/apt-pkg/versionmatch.cc index e4fa0ea6..26262a01 100644 --- a/apt-pkg/versionmatch.cc +++ b/apt-pkg/versionmatch.cc @@ -181,9 +181,9 @@ pkgCache::VerIterator pkgVersionMatch::Find(pkgCache::PkgIterator Pkg) bool pkgVersionMatch::ExpressionMatches(const char *pattern, const char *string) { if (pattern[0] == '/') { - bool res = false; size_t length = strlen(pattern); if (pattern[length - 1] == '/') { + bool res = false; regex_t preg; char *regex = strdup(pattern + 1); regex[length - 2] = '\0'; -- cgit v1.2.3 From a65e22c64a9312dec90264b4059424dbe2290d7b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 12 Mar 2013 23:28:16 +0100 Subject: * apt-pkg/pkgcachegen.cc: - do not store the MD5Sum for every description language variant as it will be the same for all so it can be shared to save cache space --- apt-pkg/pkgcachegen.cc | 61 ++++++++++++++++++++++++++------------------------ debian/changelog | 3 +++ 2 files changed, 35 insertions(+), 29 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 373f6625..2f05310c 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -300,36 +300,35 @@ bool pkgCacheGenerator::MergeListPackage(ListParser &List, pkgCache::PkgIterator for (Ver = Pkg.VersionList(); Ver.end() == false; ++Ver) { - pkgCache::DescIterator Desc = Ver.DescriptionList(); + pkgCache::DescIterator VerDesc = Ver.DescriptionList(); // a version can only have one md5 describing it - if (Desc.end() == true || MD5SumValue(Desc.md5()) != CurMd5) + if (VerDesc.end() == true || MD5SumValue(VerDesc.md5()) != CurMd5) continue; // don't add a new description if we have one for the given // md5 && language - if (IsDuplicateDescription(Desc, CurMd5, CurLang) == true) + if (IsDuplicateDescription(VerDesc, CurMd5, CurLang) == true) continue; + pkgCache::DescIterator Desc; Dynamic DynDesc(Desc); - // we add at the end, so that the start is constant as we need - // that to be able to efficiently share these lists - map_ptrloc *LastDesc = &Ver->DescriptionList; - for (;Desc.end() == false && Desc->NextDesc != 0; ++Desc); - if (Desc.end() == false) - LastDesc = &Desc->NextDesc; - void const * const oldMap = Map.Data(); - map_ptrloc const descindex = NewDescription(Desc, CurLang, CurMd5, *LastDesc); + map_ptrloc const descindex = NewDescription(Desc, CurLang, CurMd5, VerDesc->md5sum); if (unlikely(descindex == 0 && _error->PendingError())) return _error->Error(_("Error occurred while processing %s (%s%d)"), Pkg.Name(), "NewDescription", 1); - if (oldMap != Map.Data()) - LastDesc += (map_ptrloc*) Map.Data() - (map_ptrloc*) oldMap; - *LastDesc = descindex; + Desc->ParentPkg = Pkg.Index(); - if ((*LastDesc == 0 && _error->PendingError()) || NewFileDesc(Desc,List) == false) + // we add at the end, so that the start is constant as we need + // that to be able to efficiently share these lists + VerDesc = Ver.DescriptionList(); // old value might be invalid after ReMap + for (;VerDesc.end() == false && VerDesc->NextDesc != 0; ++VerDesc); + map_ptrloc * const LastNextDesc = (VerDesc.end() == true) ? &Ver->DescriptionList : &VerDesc->NextDesc; + *LastNextDesc = descindex; + + if (NewFileDesc(Desc,List) == false) return _error->Error(_("Error occurred while processing %s (%s%d)"), Pkg.Name(), "NewFileDesc", 1); @@ -509,19 +508,16 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator // We haven't found reusable descriptions, so add the first description pkgCache::DescIterator Desc = Ver.DescriptionList(); Dynamic DynDesc(Desc); - map_ptrloc *LastDesc = &Ver->DescriptionList; - oldMap = Map.Data(); - map_ptrloc const descindex = NewDescription(Desc, CurLang, CurMd5, *LastDesc); + map_ptrloc const descindex = NewDescription(Desc, CurLang, CurMd5, 0); if (unlikely(descindex == 0 && _error->PendingError())) return _error->Error(_("Error occurred while processing %s (%s%d)"), Pkg.Name(), "NewDescription", 2); - if (oldMap != Map.Data()) - LastDesc += (map_ptrloc*) Map.Data() - (map_ptrloc*) oldMap; - *LastDesc = descindex; + Desc->ParentPkg = Pkg.Index(); + Ver->DescriptionList = descindex; - if ((*LastDesc == 0 && _error->PendingError()) || NewFileDesc(Desc,List) == false) + if (NewFileDesc(Desc,List) == false) return _error->Error(_("Error occurred while processing %s (%s%d)"), Pkg.Name(), "NewFileDesc", 2); @@ -825,9 +821,9 @@ bool pkgCacheGenerator::NewFileDesc(pkgCache::DescIterator &Desc, // --------------------------------------------------------------------- /* This puts a description structure in the linked list */ map_ptrloc pkgCacheGenerator::NewDescription(pkgCache::DescIterator &Desc, - const string &Lang, - const MD5SumValue &md5sum, - map_ptrloc Next) + const string &Lang, + const MD5SumValue &md5sum, + map_ptrloc idxmd5str) { // Get a structure map_ptrloc const Description = AllocateInMap(sizeof(pkgCache::Description)); @@ -836,14 +832,21 @@ map_ptrloc pkgCacheGenerator::NewDescription(pkgCache::DescIterator &Desc, // Fill it in Desc = pkgCache::DescIterator(Cache,Cache.DescP + Description); - Desc->NextDesc = Next; Desc->ID = Cache.HeaderP->DescriptionCount++; map_ptrloc const idxlanguage_code = WriteStringInMap(Lang); - map_ptrloc const idxmd5sum = WriteStringInMap(md5sum.Value()); - if (unlikely(idxlanguage_code == 0 || idxmd5sum == 0)) + if (unlikely(idxlanguage_code == 0)) return 0; Desc->language_code = idxlanguage_code; - Desc->md5sum = idxmd5sum; + + if (idxmd5str != 0) + Desc->md5sum = idxmd5str; + else + { + map_ptrloc const idxmd5sum = WriteStringInMap(md5sum.Value()); + if (unlikely(idxmd5sum == 0)) + return 0; + Desc->md5sum = idxmd5sum; + } return Description; } diff --git a/debian/changelog b/debian/changelog index 067103c7..58cff682 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,9 @@ apt (0.9.7.8~exp2+nmu1) UNRELEASED; urgency=low [ David Kalnischkies ] * various simple changes to fix cppcheck warnings + * apt-pkg/pkgcachegen.cc: + - do not store the MD5Sum for every description language variant as + it will be the same for all so it can be shared to save cache space -- David Kalnischkies Sun, 10 Mar 2013 12:23:24 +0100 -- cgit v1.2.3 From 734b7c817a54e2717bc9124a691be532d881a65b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 12 Mar 2013 23:47:48 +0100 Subject: handle language tags for descriptions are unique strings to be shared --- apt-pkg/pkgcachegen.cc | 2 +- debian/changelog | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 2f05310c..d14a7af1 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -833,7 +833,7 @@ map_ptrloc pkgCacheGenerator::NewDescription(pkgCache::DescIterator &Desc, // Fill it in Desc = pkgCache::DescIterator(Cache,Cache.DescP + Description); Desc->ID = Cache.HeaderP->DescriptionCount++; - map_ptrloc const idxlanguage_code = WriteStringInMap(Lang); + map_ptrloc const idxlanguage_code = WriteUniqString(Lang); if (unlikely(idxlanguage_code == 0)) return 0; Desc->language_code = idxlanguage_code; diff --git a/debian/changelog b/debian/changelog index 58cff682..9578ec8f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ apt (0.9.7.8~exp2+nmu1) UNRELEASED; urgency=low * apt-pkg/pkgcachegen.cc: - do not store the MD5Sum for every description language variant as it will be the same for all so it can be shared to save cache space + - handle language tags for descriptions are unique strings to be shared -- David Kalnischkies Sun, 10 Mar 2013 12:23:24 +0100 -- cgit v1.2.3 From 9c44383f2ea09afbf6ebab217cdc450e5170c172 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 13 Mar 2013 19:00:19 +0100 Subject: factor version string creation out of NewDepends, so we can easily reuse version strings e.g. for implicit multi-arch dependencies --- apt-pkg/pkgcachegen.cc | 57 +++++++++++++++++++++++++++----------------------- apt-pkg/pkgcachegen.h | 3 +++ debian/changelog | 2 ++ 3 files changed, 36 insertions(+), 26 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index d14a7af1..01aaf616 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -463,11 +463,8 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator pkgCache::VerIterator ConVersion = D.ParentVer(); Dynamic DynV(ConVersion); // duplicate the Conflicts/Breaks/Replaces for :none arch - if (D->Version == 0) - NewDepends(Pkg, ConVersion, "", 0, D->Type, OldDepLast); - else - NewDepends(Pkg, ConVersion, D.TargetVer(), - D->CompareOp, D->Type, OldDepLast); + NewDepends(Pkg, ConVersion, D->Version, + D->CompareOp, D->Type, OldDepLast); } } } @@ -671,6 +668,7 @@ bool pkgCacheGenerator::AddImplicitDepends(pkgCache::GrpIterator &G, bool const coInstall = ((V->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same); pkgCache::PkgIterator D = G.PackageList(); Dynamic DynD(D); + map_ptrloc const VerStrIdx = V->VerStr; for (; D.end() != true; D = G.NextPkg(D)) { if (Arch == D.Arch() || D->VersionList == 0) @@ -681,16 +679,16 @@ bool pkgCacheGenerator::AddImplicitDepends(pkgCache::GrpIterator &G, if (coInstall == true) { // Replaces: ${self}:other ( << ${binary:Version}) - NewDepends(D, V, V.VerStr(), + NewDepends(D, V, VerStrIdx, pkgCache::Dep::Less, pkgCache::Dep::Replaces, OldDepLast); // Breaks: ${self}:other (!= ${binary:Version}) - NewDepends(D, V, V.VerStr(), + NewDepends(D, V, VerStrIdx, pkgCache::Dep::NotEquals, pkgCache::Dep::DpkgBreaks, OldDepLast); } else { // Conflicts: ${self}:other - NewDepends(D, V, "", + NewDepends(D, V, 0, pkgCache::Dep::NoOp, pkgCache::Dep::Conflicts, OldDepLast); } @@ -707,17 +705,18 @@ bool pkgCacheGenerator::AddImplicitDepends(pkgCache::VerIterator &V, bool const coInstall = ((V->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same); if (coInstall == true) { + map_ptrloc const VerStrIdx = V->VerStr; // Replaces: ${self}:other ( << ${binary:Version}) - NewDepends(D, V, V.VerStr(), + NewDepends(D, V, VerStrIdx, pkgCache::Dep::Less, pkgCache::Dep::Replaces, OldDepLast); // Breaks: ${self}:other (!= ${binary:Version}) - NewDepends(D, V, V.VerStr(), + NewDepends(D, V, VerStrIdx, pkgCache::Dep::NotEquals, pkgCache::Dep::DpkgBreaks, OldDepLast); } else { // Conflicts: ${self}:other - NewDepends(D, V, "", + NewDepends(D, V, 0, pkgCache::Dep::NoOp, pkgCache::Dep::Conflicts, OldDepLast); } @@ -861,35 +860,41 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg, unsigned int const &Op, unsigned int const &Type, map_ptrloc* &OldDepLast) +{ + map_ptrloc index = 0; + if (Version.empty() == false) + { + void const * const oldMap = Map.Data(); + index = WriteStringInMap(Version); + if (unlikely(index == 0)) + return false; + if (oldMap != Map.Data()) + OldDepLast += (map_ptrloc*) Map.Data() - (map_ptrloc*) oldMap; + } + return NewDepends(Pkg, Ver, index, Op, Type, OldDepLast); +} +bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg, + pkgCache::VerIterator &Ver, + map_ptrloc const Version, + unsigned int const &Op, + unsigned int const &Type, + map_ptrloc* &OldDepLast) { void const * const oldMap = Map.Data(); // Get a structure map_ptrloc const Dependency = AllocateInMap(sizeof(pkgCache::Dependency)); if (unlikely(Dependency == 0)) return false; - + // Fill it in pkgCache::DepIterator Dep(Cache,Cache.DepP + Dependency); Dynamic DynDep(Dep); Dep->ParentVer = Ver.Index(); Dep->Type = Type; Dep->CompareOp = Op; + Dep->Version = Version; Dep->ID = Cache.HeaderP->DependsCount++; - // Probe the reverse dependency list for a version string that matches - if (Version.empty() == false) - { -/* for (pkgCache::DepIterator I = Pkg.RevDependsList(); I.end() == false; I++) - if (I->Version != 0 && I.TargetVer() == Version) - Dep->Version = I->Version;*/ - if (Dep->Version == 0) { - map_ptrloc const index = WriteStringInMap(Version); - if (unlikely(index == 0)) - return false; - Dep->Version = index; - } - } - // Link it to the package Dep->Package = Pkg.Index(); Dep->NextRevDepends = Pkg->RevDepends; diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h index b6259b43..e759cbd3 100644 --- a/apt-pkg/pkgcachegen.h +++ b/apt-pkg/pkgcachegen.h @@ -77,6 +77,9 @@ class pkgCacheGenerator /*{{{*/ bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, std::string const &Version, unsigned int const &Op, unsigned int const &Type, map_ptrloc* &OldDepLast); + bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, + map_ptrloc const Version, unsigned int const &Op, + unsigned int const &Type, map_ptrloc* &OldDepLast); unsigned long NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,unsigned long Next); map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_ptrloc Next); diff --git a/debian/changelog b/debian/changelog index 9578ec8f..7796f592 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,8 @@ apt (0.9.7.8~exp2+nmu1) UNRELEASED; urgency=low - do not store the MD5Sum for every description language variant as it will be the same for all so it can be shared to save cache space - handle language tags for descriptions are unique strings to be shared + - factor version string creation out of NewDepends, so we can easily reuse + version strings e.g. for implicit multi-arch dependencies -- David Kalnischkies Sun, 10 Mar 2013 12:23:24 +0100 -- cgit v1.2.3 From 40befb065d110c7b3a7b3d37759b6888522817b2 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 1 Apr 2013 13:19:43 +0200 Subject: * apt-pkg/deb/debversion.cc: - add a string-equal shortcut for equal version comparisions --- apt-pkg/deb/debversion.cc | 15 ++++++++++++--- debian/changelog | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/debversion.cc b/apt-pkg/deb/debversion.cc index a02699a4..94d35784 100644 --- a/apt-pkg/deb/debversion.cc +++ b/apt-pkg/deb/debversion.cc @@ -215,10 +215,19 @@ bool debVersioningSystem::CheckDep(const char *PkgVer, return true; if (PkgVer == 0 || PkgVer[0] == 0) return false; - + Op &= 0x0F; + + size_t const lenPkgVer = strlen(PkgVer); + size_t const lenDepVer = strlen(DepVer); + + // take a shortcut for equals which are string-equal as well + if (Op == pkgCache::Dep::Equals && lenPkgVer == lenDepVer && + memcmp(PkgVer, DepVer, lenPkgVer) == 0) + return true; + // Perform the actual comparision. - int Res = CmpVersion(PkgVer,DepVer); - switch (Op & 0x0F) + int const Res = DoCmpVersion(PkgVer, PkgVer + lenPkgVer, DepVer, DepVer + lenDepVer); + switch (Op) { case pkgCache::Dep::LessEq: if (Res <= 0) diff --git a/debian/changelog b/debian/changelog index 7796f592..b0e66912 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,8 @@ apt (0.9.7.8~exp2+nmu1) UNRELEASED; urgency=low - handle language tags for descriptions are unique strings to be shared - factor version string creation out of NewDepends, so we can easily reuse version strings e.g. for implicit multi-arch dependencies + * apt-pkg/deb/debversion.cc: + - add a string-equal shortcut for equal version comparisions -- David Kalnischkies Sun, 10 Mar 2013 12:23:24 +0100 -- cgit v1.2.3 From b8a884c0c7d5f670179a82984289140a9f432729 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 1 Apr 2013 15:41:02 +0200 Subject: equal comparisions are used mostly in same-source relations, so use this to try to reuse some version strings --- apt-pkg/pkgcachegen.cc | 20 ++++++++++++++------ debian/changelog | 2 ++ 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 01aaf616..b11ddcf9 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -864,12 +864,20 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg, map_ptrloc index = 0; if (Version.empty() == false) { - void const * const oldMap = Map.Data(); - index = WriteStringInMap(Version); - if (unlikely(index == 0)) - return false; - if (oldMap != Map.Data()) - OldDepLast += (map_ptrloc*) Map.Data() - (map_ptrloc*) oldMap; + int const CmpOp = Op & 0x0F; + // =-deps are used (79:1) for lockstep on same-source packages (e.g. data-packages) + if (CmpOp == pkgCache::Dep::Equals && strcmp(Version.c_str(), Ver.VerStr()) == 0) + index = Ver->VerStr; + + if (index == 0) + { + void const * const oldMap = Map.Data(); + index = WriteStringInMap(Version); + if (unlikely(index == 0)) + return false; + if (oldMap != Map.Data()) + OldDepLast += (map_ptrloc*) Map.Data() - (map_ptrloc*) oldMap; + } } return NewDepends(Pkg, Ver, index, Op, Type, OldDepLast); } diff --git a/debian/changelog b/debian/changelog index b0e66912..d9183db9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,8 @@ apt (0.9.7.8~exp2+nmu1) UNRELEASED; urgency=low - handle language tags for descriptions are unique strings to be shared - factor version string creation out of NewDepends, so we can easily reuse version strings e.g. for implicit multi-arch dependencies + - equal comparisions are used mostly in same-source relations, + so use this to try to reuse some version strings * apt-pkg/deb/debversion.cc: - add a string-equal shortcut for equal version comparisions -- cgit v1.2.3 From d9682cf8268d6c69e41adb6be9f03d68ba066a12 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 1 Apr 2013 23:27:16 +0200 Subject: micro-optimize and enhance readability of ListParser::VersionHash --- apt-pkg/deb/deblistparser.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 56d5297f..67f0ac9c 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -284,7 +284,7 @@ unsigned short debListParser::VersionHash() "Replaces",0}; unsigned long Result = INIT_FCS; char S[1024]; - for (const char **I = Sections; *I != 0; I++) + for (const char * const *I = Sections; *I != 0; ++I) { const char *Start; const char *End; @@ -295,13 +295,13 @@ unsigned short debListParser::VersionHash() of certain fields. dpkg also has the rather interesting notion of reformatting depends operators < -> <= */ char *J = S; - for (; Start != End; Start++) + for (; Start != End; ++Start) { - if (isspace(*Start) == 0) - *J++ = tolower_ascii(*Start); - if (*Start == '<' && Start[1] != '<' && Start[1] != '=') - *J++ = '='; - if (*Start == '>' && Start[1] != '>' && Start[1] != '=') + if (isspace(*Start) != 0) + continue; + *J++ = tolower_ascii(*Start); + + if ((*Start == '<' || *Start == '>') && Start[1] != *Start && Start[1] != '=') *J++ = '='; } -- cgit v1.2.3 From aa0fe657e46b87cc692895a36df12e8b74bb27bb Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 3 Apr 2013 12:44:36 +0200 Subject: - sort group and package names in the hashtable on insert * apt-pkg/pkgcache.cc: - assume sorted hashtable entries for groups/packages --- apt-pkg/pkgcache.cc | 31 ++++++++++++++++++++----------- apt-pkg/pkgcachegen.cc | 16 +++++++++++----- debian/changelog | 3 +++ 3 files changed, 34 insertions(+), 16 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 1378876f..879f3409 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -52,7 +52,7 @@ pkgCache::Header::Header() /* Whenever the structures change the major version should be bumped, whenever the generator changes the minor version should be bumped. */ MajorVersion = 8; - MinorVersion = 0; + MinorVersion = 1; Dirty = false; HeaderSz = sizeof(pkgCache::Header); @@ -182,18 +182,17 @@ unsigned long pkgCache::sHash(const string &Str) const { unsigned long Hash = 0; for (string::const_iterator I = Str.begin(); I != Str.end(); ++I) - Hash = 5*Hash + tolower_ascii(*I); + Hash = 41 * Hash + tolower_ascii(*I); return Hash % _count(HeaderP->PkgHashTable); } unsigned long pkgCache::sHash(const char *Str) const { - unsigned long Hash = 0; - for (const char *I = Str; *I != 0; ++I) - Hash = 5*Hash + tolower_ascii(*I); + unsigned long Hash = tolower_ascii(*Str); + for (const char *I = Str + 1; *I != 0; ++I) + Hash = 41 * Hash + tolower_ascii(*I); return Hash % _count(HeaderP->PkgHashTable); } - /*}}}*/ // Cache::SingleArchFindPkg - Locate a package by name /*{{{*/ // --------------------------------------------------------------------- @@ -206,9 +205,14 @@ pkgCache::PkgIterator pkgCache::SingleArchFindPkg(const string &Name) 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); + if (unlikely(Pkg->Name == 0)) + continue; + + int const cmp = strcasecmp(Name.c_str(), StrP + Pkg->Name); + if (cmp == 0) + return PkgIterator(*this, Pkg); + else if (cmp < 0) + break; } return PkgIterator(*this,0); } @@ -265,9 +269,14 @@ pkgCache::GrpIterator pkgCache::FindGrp(const string &Name) { // Look at the hash bucket for the group Group *Grp = GrpP + HeaderP->GrpHashTable[sHash(Name)]; for (; Grp != GrpP; Grp = GrpP + Grp->Next) { - if (Grp->Name != 0 && StrP[Grp->Name] == Name[0] && - stringcasecmp(Name, StrP + Grp->Name) == 0) + if (unlikely(Grp->Name == 0)) + continue; + + int const cmp = strcasecmp(Name.c_str(), StrP + Grp->Name); + if (cmp == 0) return GrpIterator(*this, Grp); + else if (cmp < 0) + break; } return GrpIterator(*this,0); diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index b11ddcf9..8437dc68 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -595,8 +595,11 @@ bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, const string &Name) // Insert it into the hash table unsigned long const Hash = Cache.Hash(Name); - Grp->Next = Cache.HeaderP->GrpHashTable[Hash]; - Cache.HeaderP->GrpHashTable[Hash] = Group; + map_ptrloc *insertAt = &Cache.HeaderP->GrpHashTable[Hash]; + while (*insertAt != 0 && strcasecmp(Name.c_str(), Cache.StrP + (Cache.GrpP + *insertAt)->Name) > 0) + insertAt = &(Cache.GrpP + *insertAt)->Next; + Grp->Next = *insertAt; + *insertAt = Group; Grp->ID = Cache.HeaderP->GroupCount++; return true; @@ -625,11 +628,14 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name // Insert the package into our package list if (Grp->FirstPackage == 0) // the group is new { + Grp->FirstPackage = Package; // Insert it into the hash table unsigned long const Hash = Cache.Hash(Name); - Pkg->NextPackage = Cache.HeaderP->PkgHashTable[Hash]; - Cache.HeaderP->PkgHashTable[Hash] = Package; - Grp->FirstPackage = Package; + map_ptrloc *insertAt = &Cache.HeaderP->PkgHashTable[Hash]; + while (*insertAt != 0 && strcasecmp(Name.c_str(), Cache.StrP + (Cache.PkgP + *insertAt)->Name) > 0) + insertAt = &(Cache.PkgP + *insertAt)->NextPackage; + Pkg->NextPackage = *insertAt; + *insertAt = Package; } else // Group the Packages together { diff --git a/debian/changelog b/debian/changelog index d9183db9..d4f0e4bb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,9 @@ apt (0.9.7.8~exp2+nmu1) UNRELEASED; urgency=low version strings e.g. for implicit multi-arch dependencies - equal comparisions are used mostly in same-source relations, so use this to try to reuse some version strings + - sort group and package names in the hashtable on insert + * apt-pkg/pkgcache.cc: + - assume sorted hashtable entries for groups/packages * apt-pkg/deb/debversion.cc: - add a string-equal shortcut for equal version comparisions -- cgit v1.2.3 From 887c6940d2afc9e3110f226e4d95fc72640e3ad6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 3 Apr 2013 19:34:47 +0200 Subject: * apt-pkg/cacheiterators.h: - provide DepIterator::IsSatisfied as a nicer shorthand for DepCheck --- apt-pkg/cacheiterators.h | 2 ++ apt-pkg/depcache.cc | 25 ++++++++++--------------- apt-pkg/pkgcache.cc | 16 ++++++++++++---- debian/changelog | 2 ++ 4 files changed, 26 insertions(+), 19 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index dcd35311..179a0e96 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -286,6 +286,8 @@ class pkgCache::DepIterator : public Iterator { bool IsIgnorable(PrvIterator const &Prv) const; bool IsIgnorable(PkgIterator const &Pkg) const; bool IsMultiArchImplicit() const; + bool IsSatisfied(VerIterator const &Ver) const; + bool IsSatisfied(PrvIterator const &Prv) const; void GlobOr(DepIterator &Start,DepIterator &End); Version **AllTargets() const; bool SmartTargetPkg(PkgIterator &Result) const; diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index a48cd8b0..6a3e9bfc 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -351,18 +351,15 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res) PkgIterator Pkg = Dep.TargetPkg(); // Check the base package if (Type == NowVersion && Pkg->CurrentVer != 0) - if (VS().CheckDep(Pkg.CurrentVer().VerStr(),Dep->CompareOp, - Dep.TargetVer()) == true) + if (Dep.IsSatisfied(Pkg.CurrentVer()) == true) return true; if (Type == InstallVersion && PkgState[Pkg->ID].InstallVer != 0) - if (VS().CheckDep(PkgState[Pkg->ID].InstVerIter(*this).VerStr(), - Dep->CompareOp,Dep.TargetVer()) == true) + if (Dep.IsSatisfied(PkgState[Pkg->ID].InstVerIter(*this)) == true) return true; if (Type == CandidateVersion && PkgState[Pkg->ID].CandidateVer != 0) - if (VS().CheckDep(PkgState[Pkg->ID].CandidateVerIter(*this).VerStr(), - Dep->CompareOp,Dep.TargetVer()) == true) + if (Dep.IsSatisfied(PkgState[Pkg->ID].CandidateVerIter(*this)) == true) return true; } @@ -398,7 +395,7 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res) } // Compare the versions. - if (VS().CheckDep(P.ProvideVersion(),Dep->CompareOp,Dep.TargetVer()) == true) + if (Dep.IsSatisfied(P) == true) { Res = P.OwnerPkg(); return true; @@ -1192,14 +1189,13 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, { APT::VersionList verlist; pkgCache::VerIterator Cand = PkgState[Start.TargetPkg()->ID].CandidateVerIter(*this); - if (Cand.end() == false && VS().CheckDep(Cand.VerStr(), Start->CompareOp, Start.TargetVer()) == true) + if (Cand.end() == false && Start.IsSatisfied(Cand) == true) verlist.insert(Cand); for (PrvIterator Prv = Start.TargetPkg().ProvidesList(); Prv.end() != true; ++Prv) { pkgCache::VerIterator V = Prv.OwnerVer(); pkgCache::VerIterator Cand = PkgState[Prv.OwnerPkg()->ID].CandidateVerIter(*this); - if (Cand.end() == true || V != Cand || - VS().CheckDep(Prv.ProvideVersion(), Start->CompareOp, Start.TargetVer()) == false) + if (Cand.end() == true || V != Cand || Start.IsSatisfied(Prv) == false) continue; verlist.insert(Cand); } @@ -1407,7 +1403,7 @@ bool pkgDepCache::SetCandidateRelease(pkgCache::VerIterator TargetVer, if (Cand.end() == true) continue; // check if the current candidate is enough for the versioned dependency - and installable? - if (VS().CheckDep(P.CandVersion(), Start->CompareOp, Start.TargetVer()) == true && + if (Start.IsSatisfied(Cand) == true && (VersionState(Cand.DependsList(), DepInstall, DepCandMin, DepCandPolicy) & DepCandMin) == DepCandMin) { itsFine = true; @@ -1441,7 +1437,7 @@ bool pkgDepCache::SetCandidateRelease(pkgCache::VerIterator TargetVer, V = Match.Find(D.TargetPkg()); // check if the version from this release could satisfy the dependency - if (V.end() == true || VS().CheckDep(V.VerStr(), D->CompareOp, D.TargetVer()) == false) + if (V.end() == true || D.IsSatisfied(V) == false) { if (stillOr == true) continue; @@ -1771,7 +1767,7 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &pkg, for(VerIterator V = d.TargetPkg().VersionList(); !V.end(); ++V) { - if(_system->VS->CheckDep(V.VerStr(), d->CompareOp, d.TargetVer())) + if(d.IsSatisfied(V)) { if(debug_autoremove) { @@ -1793,8 +1789,7 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &pkg, for(PrvIterator prv=d.TargetPkg().ProvidesList(); !prv.end(); ++prv) { - if(_system->VS->CheckDep(prv.ProvideVersion(), d->CompareOp, - d.TargetVer())) + if(d.IsSatisfied(prv)) { if(debug_autoremove) { diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 879f3409..d7725563 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -634,8 +634,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() const { if (IsIgnorable(I.ParentPkg()) == true) continue; - - if (Owner->VS->CheckDep(I.VerStr(),S->CompareOp,TargetVer()) == false) + if (IsSatisfied(I) == false) continue; Size++; @@ -648,8 +647,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() const { if (IsIgnorable(I) == true) continue; - - if (Owner->VS->CheckDep(I.ProvideVersion(),S->CompareOp,TargetVer()) == false) + if (IsSatisfied(I) == false) continue; Size++; @@ -757,6 +755,16 @@ bool pkgCache::DepIterator::IsMultiArchImplicit() const return false; } /*}}}*/ +// DepIterator::IsSatisfied - check if a version satisfied the dependency /*{{{*/ +bool pkgCache::DepIterator::IsSatisfied(VerIterator const &Ver) const +{ + return Owner->VS->CheckDep(Ver.VerStr(),S->CompareOp,TargetVer()); +} +bool pkgCache::DepIterator::IsSatisfied(PrvIterator const &Prv) const +{ + return Owner->VS->CheckDep(Prv.ProvideVersion(),S->CompareOp,TargetVer()); +} + /*}}}*/ // ostream operator to handle string representation of a dependecy /*{{{*/ // --------------------------------------------------------------------- /* */ diff --git a/debian/changelog b/debian/changelog index d4f0e4bb..7070c5fc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,6 +13,8 @@ apt (0.9.7.8~exp2+nmu1) UNRELEASED; urgency=low - sort group and package names in the hashtable on insert * apt-pkg/pkgcache.cc: - assume sorted hashtable entries for groups/packages + * apt-pkg/cacheiterators.h: + - provide DepIterator::IsSatisfied as a nicer shorthand for DepCheck * apt-pkg/deb/debversion.cc: - add a string-equal shortcut for equal version comparisions -- cgit v1.2.3 From 885594fc8831d1be5a254557385e3dbefb564fbf Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 3 Apr 2013 19:43:03 +0200 Subject: share version strings between same versions (of different architectures) to save some space and allow quick comparisions later on --- apt-pkg/deb/debversion.cc | 12 ++++-------- apt-pkg/pkgcachegen.cc | 37 +++++++++++++++++++++++++++++++------ apt-pkg/pkgcachegen.h | 6 +++++- debian/changelog | 2 ++ 4 files changed, 42 insertions(+), 15 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/debversion.cc b/apt-pkg/deb/debversion.cc index 94d35784..14056126 100644 --- a/apt-pkg/deb/debversion.cc +++ b/apt-pkg/deb/debversion.cc @@ -217,16 +217,12 @@ bool debVersioningSystem::CheckDep(const char *PkgVer, return false; Op &= 0x0F; - size_t const lenPkgVer = strlen(PkgVer); - size_t const lenDepVer = strlen(DepVer); - - // take a shortcut for equals which are string-equal as well - if (Op == pkgCache::Dep::Equals && lenPkgVer == lenDepVer && - memcmp(PkgVer, DepVer, lenPkgVer) == 0) - return true; + // fast track for (equal) strings [by location] which are by definition equal versions + if (PkgVer == DepVer) + return Op == pkgCache::Dep::Equals || Op == pkgCache::Dep::LessEq || Op == pkgCache::Dep::GreaterEq; // Perform the actual comparision. - int const Res = DoCmpVersion(PkgVer, PkgVer + lenPkgVer, DepVer, DepVer + lenDepVer); + int const Res = CmpVersion(PkgVer, DepVer); switch (Op) { case pkgCache::Dep::LessEq: diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 8437dc68..3f10b6c4 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -390,7 +390,7 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator } // Add a new version - map_ptrloc const verindex = NewVersion(Ver,Version,*LastVer); + map_ptrloc const verindex = NewVersion(Ver, Version, Pkg.Index(), Hash, *LastVer); if (verindex == 0 && _error->PendingError()) return _error->Error(_("Error occurred while processing %s (%s%d)"), Pkg.Name(), "NewVersion", 1); @@ -398,8 +398,6 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator if (oldMap != Map.Data()) LastVer += (map_ptrloc*) Map.Data() - (map_ptrloc*) oldMap; *LastVer = verindex; - Ver->ParentPkg = Pkg.Index(); - Ver->Hash = Hash; if (unlikely(List.NewVersion(Ver) == false)) return _error->Error(_("Error occurred while processing %s (%s%d)"), @@ -557,7 +555,7 @@ bool pkgCacheGenerator::MergeFileProvides(ListParser &List) Dynamic DynVer(Ver); for (; Ver.end() == false; ++Ver) { - if (Ver->Hash == Hash && Version.c_str() == Ver.VerStr()) + if (Ver->Hash == Hash && Version == Ver.VerStr()) { if (List.CollectFileProvides(Cache,Ver) == false) return _error->Error(_("Error occurred while processing %s (%s%d)"), @@ -768,6 +766,8 @@ bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver, /* This puts a version structure in the linked list */ unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver, const string &VerStr, + map_ptrloc const ParentPkg, + unsigned long const Hash, unsigned long Next) { // Get a structure @@ -779,12 +779,37 @@ unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver, Ver = pkgCache::VerIterator(Cache,Cache.VerP + Version); //Dynamic DynV(Ver); // caller MergeListVersion already takes care of it Ver->NextVer = Next; + Ver->ParentPkg = ParentPkg; + Ver->Hash = Hash; Ver->ID = Cache.HeaderP->VersionCount++; + + // try to find the version string in the group for reuse + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + pkgCache::GrpIterator Grp = Pkg.Group(); + if (Pkg.end() == false && Grp.end() == false) + { + for (pkgCache::PkgIterator P = Grp.PackageList(); P.end() == false; P = Grp.NextPkg(P)) + { + if (Pkg == P) + continue; + for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V) + { + int const cmp = strcmp(V.VerStr(), VerStr.c_str()); + if (cmp == 0) + { + Ver->VerStr = V->VerStr; + return Version; + } + else if (cmp < 0) + break; + } + } + } + // haven't found the version string, so create map_ptrloc const idxVerStr = WriteStringInMap(VerStr); if (unlikely(idxVerStr == 0)) return 0; Ver->VerStr = idxVerStr; - return Version; } /*}}}*/ @@ -881,7 +906,7 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg, index = WriteStringInMap(Version); if (unlikely(index == 0)) return false; - if (oldMap != Map.Data()) + if (OldDepLast != 0 && oldMap != Map.Data()) OldDepLast += (map_ptrloc*) Map.Data() - (map_ptrloc*) oldMap; } } diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h index e759cbd3..428e8459 100644 --- a/apt-pkg/pkgcachegen.h +++ b/apt-pkg/pkgcachegen.h @@ -80,7 +80,11 @@ class pkgCacheGenerator /*{{{*/ bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, map_ptrloc const Version, unsigned int const &Op, unsigned int const &Type, map_ptrloc* &OldDepLast); - unsigned long NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,unsigned long Next); + __deprecated unsigned long NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,unsigned long Next) + { return NewVersion(Ver, VerStr, 0, 0, Next); } + unsigned long NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr, + map_ptrloc const ParentPkg, unsigned long const Hash, + unsigned long Next); map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_ptrloc Next); public: diff --git a/debian/changelog b/debian/changelog index 7070c5fc..9fce4b14 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,8 @@ apt (0.9.7.8~exp2+nmu1) UNRELEASED; urgency=low - equal comparisions are used mostly in same-source relations, so use this to try to reuse some version strings - sort group and package names in the hashtable on insert + - share version strings between same versions (of different architectures) + to save some space and allow quick comparisions later on * apt-pkg/pkgcache.cc: - assume sorted hashtable entries for groups/packages * apt-pkg/cacheiterators.h: -- cgit v1.2.3