From 49521f87851089bdb4097b715d09a8bd348aa60a Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 28 Sep 2016 00:49:45 +0200 Subject: Do not use MD5SumValue for Description_md5() Our profile says we spend about 5% of the time transforming the hex digits into the binary format used by HashsumValue, all for comparing them against the other strings. That makes no sense at all. According to callgrind, this reduces the overall instruction count from 5,3 billion to 5 billion in my example, which roughly matches the 5%. --- apt-pkg/pkgcachegen.cc | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'apt-pkg/pkgcachegen.cc') diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 1d997678c..107f1f141 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -45,8 +45,8 @@ template using Dynamic = pkgCacheGenerator::Dynamic; typedef std::vector::iterator FileIterator; template std::vector pkgCacheGenerator::Dynamic::toReMap; -static bool IsDuplicateDescription(pkgCache::DescIterator Desc, - MD5SumValue const &CurMd5, std::string const &CurLang); +static bool IsDuplicateDescription(pkgCache &Cache, pkgCache::DescIterator Desc, + APT::StringView CurMd5, std::string const &CurLang); using std::string; using APT::StringView; @@ -340,14 +340,14 @@ bool pkgCacheGenerator::MergeListPackage(ListParser &List, pkgCache::PkgIterator Pkg.Name(), "UsePackage", 1); // Find the right version to write the description - MD5SumValue CurMd5 = List.Description_md5(); + StringView CurMd5 = List.Description_md5(); std::vector availDesc = List.AvailableDescriptionLanguages(); for (Ver = Pkg.VersionList(); Ver.end() == false; ++Ver) { pkgCache::DescIterator VerDesc = Ver.DescriptionList(); // a version can only have one md5 describing it - if (VerDesc.end() == true || MD5SumValue(VerDesc.md5()) != CurMd5) + if (VerDesc.end() == true || Cache.ViewString(VerDesc->md5sum) != CurMd5) continue; map_stringitem_t md5idx = VerDesc->md5sum; @@ -355,7 +355,7 @@ bool pkgCacheGenerator::MergeListPackage(ListParser &List, pkgCache::PkgIterator { // don't add a new description if we have one for the given // md5 && language - if (IsDuplicateDescription(VerDesc, CurMd5, *CurLang) == true) + if (IsDuplicateDescription(Cache, VerDesc, CurMd5, *CurLang) == true) continue; AddNewDescription(List, Ver, *CurLang, CurMd5, md5idx); @@ -489,7 +489,7 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator } /* Record the Description(s) based on their master md5sum */ - MD5SumValue CurMd5 = List.Description_md5(); + StringView CurMd5 = List.Description_md5(); /* Before we add a new description we first search in the group for a version with a description of the same MD5 - if so we reuse this @@ -500,7 +500,7 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V) { - if (V->DescriptionList == 0 || MD5SumValue(V.DescriptionList().md5()) != CurMd5) + if (V->DescriptionList == 0 || Cache.ViewString(V.DescriptionList()->md5sum) != CurMd5) continue; Ver->DescriptionList = V->DescriptionList; } @@ -515,7 +515,7 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator return true; } /*}}}*/ -bool pkgCacheGenerator::AddNewDescription(ListParser &List, pkgCache::VerIterator &Ver, std::string const &lang, MD5SumValue const &CurMd5, map_stringitem_t &md5idx) /*{{{*/ +bool pkgCacheGenerator::AddNewDescription(ListParser &List, pkgCache::VerIterator &Ver, std::string const &lang, APT::StringView CurMd5, map_stringitem_t &md5idx) /*{{{*/ { pkgCache::DescIterator Desc; Dynamic DynDesc(Desc); @@ -935,7 +935,7 @@ bool pkgCacheGenerator::NewFileDesc(pkgCache::DescIterator &Desc, /* This puts a description structure in the linked list */ map_pointer_t pkgCacheGenerator::NewDescription(pkgCache::DescIterator &Desc, const string &Lang, - const MD5SumValue &md5sum, + APT::StringView md5sum, map_stringitem_t const idxmd5str) { // Get a structure @@ -955,7 +955,7 @@ map_pointer_t pkgCacheGenerator::NewDescription(pkgCache::DescIterator &Desc, Desc->md5sum = idxmd5str; else { - map_stringitem_t const idxmd5sum = WriteStringInMap(md5sum.Value()); + map_stringitem_t const idxmd5sum = WriteStringInMap(md5sum); if (unlikely(idxmd5sum == 0)) return 0; Desc->md5sum = idxmd5sum; @@ -1839,11 +1839,11 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O } /*}}}*/ // IsDuplicateDescription /*{{{*/ -static bool IsDuplicateDescription(pkgCache::DescIterator Desc, - MD5SumValue const &CurMd5, std::string const &CurLang) +static bool IsDuplicateDescription(pkgCache &Cache, pkgCache::DescIterator Desc, + APT::StringView CurMd5, std::string const &CurLang) { // Descriptions in the same link-list have all the same md5 - if (Desc.end() == true || MD5SumValue(Desc.md5()) != CurMd5) + if (Desc.end() == true || Cache.ViewString(Desc->md5sum) != CurMd5) return false; for (; Desc.end() == false; ++Desc) if (Desc.LanguageCode() == CurLang) -- cgit v1.2.3