From 23dba65f031954df896bc3c6dfb1a9705574886b Mon Sep 17 00:00:00 2001 From: Herman Semenoff Date: Wed, 8 Apr 2026 12:58:55 +0300 Subject: apt: modernize to make_unique C++17 References: - https://stackoverflow.com/questions/79700634/pros-and-cons-of-make-unique-vs-direct-constructor-call-in-c17 - https://towardsdev.com/why-std-make-unique-beats-new-in-modern-c-7e2ba653737e - https://www.sololearn.com/en/Discuss/3334779/where-make_unique-is-better-than-unique_ptrraw-pointer --- apt-pkg/pkgcachegen.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'apt-pkg/pkgcachegen.cc') diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 7bf635972..82b88d6b0 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -1502,10 +1502,10 @@ static bool CheckValidity(FileFd &CacheFile, std::string const &CacheFileName, } // Map it - std::unique_ptr Map(new MMap(CacheFile,0)); + auto Map = std::make_unique(CacheFile,0); if (unlikely(Map->validData()) == false) return false; - std::unique_ptr CacheP(new pkgCache(Map.get())); + auto CacheP = std::make_unique(Map.get()); pkgCache &Cache = *CacheP.get(); if (_error->PendingError() || Map->Size() == 0) { @@ -1514,7 +1514,7 @@ static bool CheckValidity(FileFd &CacheFile, std::string const &CacheFileName, return false; } - std::unique_ptr RlsVisited(new bool[Cache.HeaderP->ReleaseFileCount]); + auto RlsVisited = std::make_unique(Cache.HeaderP->ReleaseFileCount); memset(RlsVisited.get(),0,sizeof(RlsVisited[0])*Cache.HeaderP->ReleaseFileCount); std::vector Files; for (pkgSourceList::const_iterator i = List.begin(); i != List.end(); ++i) @@ -1549,7 +1549,7 @@ static bool CheckValidity(FileFd &CacheFile, std::string const &CacheFileName, /* Now we check every index file, see if it is in the cache, verify the IMS data and check that it is on the disk too.. */ - std::unique_ptr Visited(new bool[Cache.HeaderP->PackageFileCount]); + auto Visited = std::make_unique(Cache.HeaderP->PackageFileCount); memset(Visited.get(),0,sizeof(Visited[0])*Cache.HeaderP->PackageFileCount); for (std::vector::const_reverse_iterator PkgFile = Files.rbegin(); PkgFile != Files.rend(); ++PkgFile) { @@ -1927,7 +1927,7 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O return false; ScopedErrorMerge sem; - std::unique_ptr Map(CreateDynamicMMap(NULL, 0)); + auto Map = std::make_unique(NULL, 0); if (unlikely(Map->validData()) == false) return false; map_filesize_t CurrentSize = 0; -- cgit v1.2.3-70-g09d2