summaryrefslogtreecommitdiff
path: root/apt-pkg/sourcelist.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-08-29 12:28:24 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-08-29 12:33:30 +0200
commit8dd562a894c2472e3705fe13c212f665b55744a9 (patch)
treea042b35a689ba64e0a76207115fb937cefa8f0c2 /apt-pkg/sourcelist.cc
parentd7a51997c30b2098bb60b3397095ec58ec825303 (diff)
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
Diffstat (limited to 'apt-pkg/sourcelist.cc')
-rw-r--r--apt-pkg/sourcelist.cc51
1 files changed, 22 insertions, 29 deletions
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<pkgIndexFile *> 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<pkgIndexFile *> *Indexes = (*I)->GetIndexFiles();
- for (vector<pkgIndexFile *>::const_iterator J = Indexes->begin();
- J != Indexes->end(); ++J)
- {
- if ((*J)->FindInCache(*File.Cache()) == File)
- {
- Found = (*J);
- return true;
- }
- }
- }
- for (vector<pkgIndexFile *>::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<string>::const_iterator I = List.begin(); I != List.end(); ++I)
- mtime_sources = std::max(mtime_sources, GetModificationTime(*I));
-
- return mtime_sources;
+ std::vector<time_t> 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<pkgIndexFile*> pkgSourceList::GetVolatileFiles() const /*{{{*/