From 8dd562a894c2472e3705fe13c212f665b55744a9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 29 Aug 2015 12:28:24 +0200 Subject: use c++11 algorithms to avoid strange compiler warnings Nobody knows what makes the 'unable to optimize loop' warning to appear in the sourceslist minus-options parsing, especially if we use a foreach loop, but we can replace it with some nice c++11 algorithm+lambda usage, which also helps in making even clearer what happens here. And as this would be a lonely change, lets do it for a few more loops as well where I might or might not have seen the warning at some point in time, too. Git-Dch: Ignore --- apt-pkg/sourcelist.cc | 51 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) (limited to 'apt-pkg/sourcelist.cc') diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index c0b416820..b083da936 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -322,7 +322,7 @@ void pkgSourceList::Reset() { for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I) delete *I; - SrcList.erase(SrcList.begin(),SrcList.end()); + SrcList.clear(); } /*}}}*/ // SourceList::Read - Parse the sourcelist file /*{{{*/ @@ -441,34 +441,26 @@ bool pkgSourceList::ParseFileDeb822(string const &File) } /*}}}*/ // SourceList::FindIndex - Get the index associated with a file /*{{{*/ -// --------------------------------------------------------------------- -/* */ +static bool FindInIndexFileContainer(std::vector const &Cont, pkgCache::PkgFileIterator const &File, pkgIndexFile *&Found) +{ + auto const J = std::find_if(Cont.begin(), Cont.end(), [&File](pkgIndexFile const * const J) { + return J->FindInCache(*File.Cache()) == File; + }); + if (J != Cont.end()) + { + Found = (*J); + return true; + } + return false; +} bool pkgSourceList::FindIndex(pkgCache::PkgFileIterator File, pkgIndexFile *&Found) const { for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I) - { - vector *Indexes = (*I)->GetIndexFiles(); - for (vector::const_iterator J = Indexes->begin(); - J != Indexes->end(); ++J) - { - if ((*J)->FindInCache(*File.Cache()) == File) - { - Found = (*J); - return true; - } - } - } - for (vector::const_iterator J = VolatileFiles.begin(); - J != VolatileFiles.end(); ++J) - { - if ((*J)->FindInCache(*File.Cache()) == File) - { - Found = (*J); + if (FindInIndexFileContainer(*(*I)->GetIndexFiles(), File, Found)) return true; - } - } - return false; + + return FindInIndexFileContainer(VolatileFiles, File, Found); } /*}}}*/ // SourceList::GetIndexes - Load the index files into the downloader /*{{{*/ @@ -517,11 +509,12 @@ time_t pkgSourceList::GetLastModifiedTime() List = GetListOfFilesInDir(Parts, "list", true); // calculate the time - time_t mtime_sources = GetModificationTime(Main); - for (vector::const_iterator I = List.begin(); I != List.end(); ++I) - mtime_sources = std::max(mtime_sources, GetModificationTime(*I)); - - return mtime_sources; + std::vector modtimes; + modtimes.reserve(1 + List.size()); + modtimes.push_back(GetModificationTime(Main)); + std::transform(List.begin(), List.end(), std::back_inserter(modtimes), GetModificationTime); + auto const maxmtime = std::max_element(modtimes.begin(), modtimes.end()); + return *maxmtime; } /*}}}*/ std::vector pkgSourceList::GetVolatileFiles() const /*{{{*/ -- cgit v1.2.3