diff options
author | Julian Andres Klode <jak@debian.org> | 2016-05-10 18:32:06 +0200 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2016-05-10 18:32:06 +0200 |
commit | a9c2517e9ce961a761022dfa8eb0b62f68f5df9e (patch) | |
tree | a60d49072c2b29d0d582b9b9e384932e48e67921 | |
parent | 33190fe3d3c200dcd417cd336f9db11f5f4408d5 (diff) | |
parent | 326a2ecfa9c6fa9d6941d7133e698510d7355ded (diff) |
Merge pull request julian-klode/apt#3 from adrian17/master
Improve GetLocalitySortedVersionSet, speeds up apt search by 30%
-rw-r--r-- | apt-pkg/contrib/strutl.cc | 4 | ||||
-rw-r--r-- | apt-private/private-cacheset.h | 29 |
2 files changed, 22 insertions, 11 deletions
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index d388cbda3..24fca5174 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -71,14 +71,14 @@ bool Endswith(const std::string &s, const std::string &end) { if (end.size() > s.size()) return false; - return (s.substr(s.size() - end.size(), s.size()) == end); + return (s.compare(s.size() - end.size(), end.size(), end) == 0); } bool Startswith(const std::string &s, const std::string &start) { if (start.size() > s.size()) return false; - return (s.substr(0, start.size()) == start); + return (s.compare(0, start.size(), start) == 0); } } diff --git a/apt-private/private-cacheset.h b/apt-private/private-cacheset.h index 0f7430fa0..4a43155fe 100644 --- a/apt-private/private-cacheset.h +++ b/apt-private/private-cacheset.h @@ -15,17 +15,28 @@ class OpProgress; +class VerIteratorWithCaching +{ + const pkgCache::VerIterator iter; + const pkgCache::DescFile * descFile; +public: + VerIteratorWithCaching(const pkgCache::VerIterator& iter) : + iter(iter), + descFile(iter->DescriptionList != 0 + ? (const pkgCache::DescFile *) iter.TranslatedDescription().FileList() + : nullptr) + {} + const pkgCache::DescFile * CachedDescFile() const { return descFile; } + operator pkgCache::VerIterator() const { return iter; } +}; + struct VersionSortDescriptionLocality /*{{{*/ { - bool operator () (const pkgCache::VerIterator &v_lhs, - const pkgCache::VerIterator &v_rhs) + bool operator () (const VerIteratorWithCaching &v_lhs, + const VerIteratorWithCaching &v_rhs) { - pkgCache::DescFile const *A = nullptr; - pkgCache::DescFile const *B = nullptr; - if (v_lhs->DescriptionList != 0) - A = v_lhs.TranslatedDescription().FileList(); - if (v_rhs->DescriptionList != 0) - B = v_rhs.TranslatedDescription().FileList(); + pkgCache::DescFile const *A = v_lhs.CachedDescFile(); + pkgCache::DescFile const *B = v_rhs.CachedDescFile(); if (A == nullptr && B == nullptr) return false; @@ -45,7 +56,7 @@ struct VersionSortDescriptionLocality /*{{{*/ /*}}}*/ // sorted by locality which makes iterating much faster typedef APT::VersionContainer< - std::set<pkgCache::VerIterator, + std::set<VerIteratorWithCaching, VersionSortDescriptionLocality> > LocalitySortedVersionSet; class Matcher { |