[devel] [PATCH for apt v4] Additional loops improvements and beautification

Aleksei Nikiforov darktemplar на altlinux.org
Пт Дек 13 12:18:45 MSK 2019


Reduce iterators scope.
Update loop conditions and iteration expressions.
---
 apt/cmdline/apt-get.cc   | 12 +++++-------
 apt/cmdline/apt-shell.cc |  2 +-
 apt/methods/http.cc      |  2 +-
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/apt/cmdline/apt-get.cc b/apt/cmdline/apt-get.cc
index 74993e6..535df0a 100644
--- a/apt/cmdline/apt-get.cc
+++ b/apt/cmdline/apt-get.cc
@@ -542,8 +542,7 @@ bool DownloadPackages(vector<string> &URLLst)
    pkgAcquire Fetcher(&Stat);
 
    // Load the requestd sources into the fetcher
-   vector<string>::const_iterator I = URLLst.begin();
-   for (; I != URLLst.end(); ++I)
+   for (auto I = URLLst.begin(); I != URLLst.end(); ++I)
       new pkgAcqFile(&Fetcher,*I,"",0,*I,flNotDir(*I));
    
    // Run it
@@ -1722,8 +1721,7 @@ bool DoDSelectUpgrade(CommandLine &CmdL)
       return false;
    
    // Install everything with the install flag set
-   pkgCache::PkgIterator I = Cache->PkgBegin();
-   for (;I.end() != true; I++)
+   for (auto I = Cache->PkgBegin(); not I.end(); ++I)
    {
       /* Install the package only if it is a new install, the autoupgrader
          will deal with the rest */
@@ -1733,7 +1731,7 @@ bool DoDSelectUpgrade(CommandLine &CmdL)
 
    /* Now install their deps too, if we do this above then order of
       the status file is significant for | groups */
-   for (I = Cache->PkgBegin();I.end() != true; I++)
+   for (auto I = Cache->PkgBegin(); not I.end(); ++I)
    {
       /* Install the package only if it is a new install, the autoupgrader
          will deal with the rest */
@@ -1742,7 +1740,7 @@ bool DoDSelectUpgrade(CommandLine &CmdL)
    }
    
    // Apply erasures now, they override everything else.
-   for (I = Cache->PkgBegin();I.end() != true; I++)
+   for (auto I = Cache->PkgBegin(); not I.end(); ++I)
    {
       // Remove packages 
       if (I->SelectedState == pkgCache::State::DeInstall ||
@@ -1759,7 +1757,7 @@ bool DoDSelectUpgrade(CommandLine &CmdL)
       // Hold back held packages.
       if (_config->FindB("APT::Ignore-Hold",false) == false)
       {
-	 for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() == false; I++)
+	 for (auto I = Cache->PkgBegin(); not I.end(); ++I)
 	 {
 	    if (I->SelectedState == pkgCache::State::Hold)
 	    {
diff --git a/apt/cmdline/apt-shell.cc b/apt/cmdline/apt-shell.cc
index b9ae00d..3a6748b 100644
--- a/apt/cmdline/apt-shell.cc
+++ b/apt/cmdline/apt-shell.cc
@@ -3050,7 +3050,7 @@ bool DoList(CommandLine &CmdL)
 	    if (Pkg->CurrentVer != 0)
 	    {
 	        status = "installed";
-              for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false; D++)
+              for (pkgCache::DepIterator D = Pkg.RevDependsList(); not D.end(); ++D)
                {
 	          pkgCache::PkgIterator P = D.ParentPkg();
                   if ((P->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential &&
diff --git a/apt/methods/http.cc b/apt/methods/http.cc
index 75b6873..c9a37de 100644
--- a/apt/methods/http.cc
+++ b/apt/methods/http.cc
@@ -386,7 +386,7 @@ int ServerState::RunHeaders()
       if (Debug == true)
 	 clog << Data;
       
-      for (string::const_iterator I = Data.begin(); I < Data.end(); ++I)
+      for (string::const_iterator I = Data.begin(); I != Data.end(); ++I)
       {
 	 string::const_iterator J = I;
 	 for (; J != Data.end() && *J != '\n' && *J != '\r';++J);
-- 
2.24.1



Подробная информация о списке рассылки Devel