summaryrefslogtreecommitdiff
path: root/apt-pkg/pkgcachegen.cc
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/pkgcachegen.cc')
-rw-r--r--apt-pkg/pkgcachegen.cc74
1 files changed, 33 insertions, 41 deletions
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index 26cf7fc68..b4fd0641e 100644
--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -37,6 +37,8 @@
#include <apti18n.h>
/*}}}*/
+constexpr auto APT_CACHE_START_DEFAULT = 24 * 1024 * 1024;
+
template<class T> using Dynamic = pkgCacheGenerator::Dynamic<T>;
typedef std::vector<pkgIndexFile *>::iterator FileIterator;
template <typename Iter> std::vector<Iter*> pkgCacheGenerator::Dynamic<Iter>::toReMap;
@@ -156,13 +158,14 @@ pkgCacheGenerator::~pkgCacheGenerator()
Map.Sync(0,sizeof(pkgCache::Header));
}
/*}}}*/
-void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newMap, size_t oldSize) {/*{{{*/
+void pkgCacheGenerator::ReMap(void const * const oldMap, void * const newMap, size_t oldSize) {/*{{{*/
+ if (oldMap == newMap)
+ return;
+
// Prevent multiple remaps of the same iterator. If seen.insert(iterator)
// returns (something, true) the iterator was not yet seen and we can
// remap it.
std::unordered_set<void *> seen;
- if (oldMap == newMap)
- return;
if (_config->FindB("Debug::pkgCacheGen", false))
std::clog << "Remapping from " << oldMap << " to " << newMap << std::endl;
@@ -170,42 +173,24 @@ void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newM
Cache.ReMap(false);
if (CurrentFile != nullptr)
- CurrentFile += static_cast<pkgCache::PackageFile const *>(newMap) - static_cast<pkgCache::PackageFile const *>(oldMap);
+ CurrentFile = static_cast<pkgCache::PackageFile *>(newMap) + (CurrentFile - static_cast<pkgCache::PackageFile const *>(oldMap));
if (CurrentRlsFile != nullptr)
- CurrentRlsFile += static_cast<pkgCache::ReleaseFile const *>(newMap) - static_cast<pkgCache::ReleaseFile const *>(oldMap);
-
- for (std::vector<pkgCache::GrpIterator*>::const_iterator i = Dynamic<pkgCache::GrpIterator>::toReMap.begin();
- i != Dynamic<pkgCache::GrpIterator>::toReMap.end(); ++i)
- if (std::get<1>(seen.insert(*i)) == true)
- (*i)->ReMap(oldMap, newMap);
- for (std::vector<pkgCache::PkgIterator*>::const_iterator i = Dynamic<pkgCache::PkgIterator>::toReMap.begin();
- i != Dynamic<pkgCache::PkgIterator>::toReMap.end(); ++i)
- if (std::get<1>(seen.insert(*i)) == true)
- (*i)->ReMap(oldMap, newMap);
- for (std::vector<pkgCache::VerIterator*>::const_iterator i = Dynamic<pkgCache::VerIterator>::toReMap.begin();
- i != Dynamic<pkgCache::VerIterator>::toReMap.end(); ++i)
- if (std::get<1>(seen.insert(*i)) == true)
- (*i)->ReMap(oldMap, newMap);
- for (std::vector<pkgCache::DepIterator*>::const_iterator i = Dynamic<pkgCache::DepIterator>::toReMap.begin();
- i != Dynamic<pkgCache::DepIterator>::toReMap.end(); ++i)
- if (std::get<1>(seen.insert(*i)) == true)
- (*i)->ReMap(oldMap, newMap);
- for (std::vector<pkgCache::DescIterator*>::const_iterator i = Dynamic<pkgCache::DescIterator>::toReMap.begin();
- i != Dynamic<pkgCache::DescIterator>::toReMap.end(); ++i)
- if (std::get<1>(seen.insert(*i)) == true)
- (*i)->ReMap(oldMap, newMap);
- for (std::vector<pkgCache::PrvIterator*>::const_iterator i = Dynamic<pkgCache::PrvIterator>::toReMap.begin();
- i != Dynamic<pkgCache::PrvIterator>::toReMap.end(); ++i)
- if (std::get<1>(seen.insert(*i)) == true)
- (*i)->ReMap(oldMap, newMap);
- for (std::vector<pkgCache::PkgFileIterator*>::const_iterator i = Dynamic<pkgCache::PkgFileIterator>::toReMap.begin();
- i != Dynamic<pkgCache::PkgFileIterator>::toReMap.end(); ++i)
- if (std::get<1>(seen.insert(*i)) == true)
- (*i)->ReMap(oldMap, newMap);
- for (std::vector<pkgCache::RlsFileIterator*>::const_iterator i = Dynamic<pkgCache::RlsFileIterator>::toReMap.begin();
- i != Dynamic<pkgCache::RlsFileIterator>::toReMap.end(); ++i)
- if (std::get<1>(seen.insert(*i)) == true)
- (*i)->ReMap(oldMap, newMap);
+ CurrentRlsFile = static_cast<pkgCache::ReleaseFile *>(newMap) + (CurrentRlsFile - static_cast<pkgCache::ReleaseFile const *>(oldMap));
+
+#define APT_REMAP(TYPE) \
+ for (auto * const i : Dynamic<TYPE>::toReMap) \
+ if (seen.insert(i).second) \
+ i->ReMap(oldMap, newMap)
+ APT_REMAP(pkgCache::GrpIterator);
+ APT_REMAP(pkgCache::PkgIterator);
+ APT_REMAP(pkgCache::VerIterator);
+ APT_REMAP(pkgCache::DepIterator);
+ APT_REMAP(pkgCache::DescIterator);
+ APT_REMAP(pkgCache::PrvIterator);
+ APT_REMAP(pkgCache::PkgFileIterator);
+ APT_REMAP(pkgCache::RlsFileIterator);
+#undef APT_REMAP
+
for (APT::StringView* ViewP : Dynamic<APT::StringView>::toReMap) {
if (std::get<1>(seen.insert(ViewP)) == false)
continue;
@@ -453,7 +438,7 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator
Pkg.Name(), "NewVersion", 1);
if (oldMap != Map.Data())
- LastVer += static_cast<map_pointer<pkgCache::Version> const *>(Map.Data()) - static_cast<map_pointer<pkgCache::Version> const *>(oldMap);
+ LastVer = static_cast<map_pointer<pkgCache::Version> *>(Map.Data()) + (LastVer - static_cast<map_pointer<pkgCache::Version> const *>(oldMap));
*LastVer = verindex;
if (unlikely(List.NewVersion(Ver) == false))
@@ -1073,7 +1058,7 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg,
for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; ++D)
OldDepLast = &D->NextDepends;
} else if (oldMap != Map.Data())
- OldDepLast += static_cast<map_pointer<pkgCache::Dependency> const *>(Map.Data()) - static_cast<map_pointer<pkgCache::Dependency> const *>(oldMap);
+ OldDepLast = static_cast<map_pointer<pkgCache::Dependency> *>(Map.Data()) + (OldDepLast - static_cast<map_pointer<pkgCache::Dependency> const *>(oldMap));
Dep->NextDepends = *OldDepLast;
*OldDepLast = Dependency;
@@ -1400,6 +1385,13 @@ static bool CheckValidity(FileFd &CacheFile, std::string const &CacheFileName,
return false;
}
+ if (_config->FindI("APT::Cache-Start", 0) == 0)
+ {
+ auto const size = CacheFile.FileSize();
+ if (std::numeric_limits<int>::max() >= size && size > APT_CACHE_START_DEFAULT)
+ _config->Set("APT::Cache-Start", size);
+ }
+
if (List.GetLastModifiedTime() > CacheFile.ModificationTime())
{
if (Debug == true)
@@ -1608,7 +1600,7 @@ static bool BuildCache(pkgCacheGenerator &Gen,
where it builds the cache 'fast' into a memory buffer. */
static DynamicMMap* CreateDynamicMMap(FileFd * const CacheF, unsigned long Flags)
{
- map_filesize_t const MapStart = _config->FindI("APT::Cache-Start", 24*1024*1024);
+ map_filesize_t const MapStart = _config->FindI("APT::Cache-Start", APT_CACHE_START_DEFAULT);
map_filesize_t const MapGrow = _config->FindI("APT::Cache-Grow", 1*1024*1024);
map_filesize_t const MapLimit = _config->FindI("APT::Cache-Limit", 0);
Flags |= MMap::Moveable;