From d40c270676bc31aa8f69e78208ca158e00b24837 Mon Sep 17 00:00:00 2001
From: Ben Boeckel <ben.boeckel@kitware.com>
Date: Sat, 8 Feb 2014 03:46:31 -0500
Subject: [PATCH] SystemTools: Remove redundant if guards

If the container is empty, the loop will be a no-op anyways, so simplify
the code a bit

Change-Id: I641b93744ff677dd1d8f78a6ad88ea0aa284fa39
---
 SystemTools.cxx | 36 +++++++++++++++---------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/SystemTools.cxx b/SystemTools.cxx
index b19f6f99..392ca8cc 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -2595,18 +2595,15 @@ kwsys_stl::string SystemTools::FindProgram(
   kwsys_stl::string tryPath;
 
   // first try with extensions if the os supports them
-  if(extensions.size())
+  for(kwsys_stl::vector<kwsys_stl::string>::iterator i =
+        extensions.begin(); i != extensions.end(); ++i)
     {
-    for(kwsys_stl::vector<kwsys_stl::string>::iterator i =
-          extensions.begin(); i != extensions.end(); ++i)
+    tryPath = name;
+    tryPath += *i;
+    if(SystemTools::FileExists(tryPath.c_str()) &&
+        !SystemTools::FileIsDirectory(tryPath.c_str()))
       {
-      tryPath = name;
-      tryPath += *i;
-      if(SystemTools::FileExists(tryPath.c_str()) &&
-         !SystemTools::FileIsDirectory(tryPath.c_str()))
-        {
-        return SystemTools::CollapseFullPath(tryPath.c_str());
-        }
+      return SystemTools::CollapseFullPath(tryPath.c_str());
       }
     }
   // now try just the name
@@ -2652,19 +2649,16 @@ kwsys_stl::string SystemTools::FindProgram(
     SystemTools::ReplaceString(*p, "\"", "");
 #endif
     // first try with extensions
-    if(extensions.size())
+    for(kwsys_stl::vector<kwsys_stl::string>::iterator ext
+          = extensions.begin(); ext != extensions.end(); ++ext)
       {
-      for(kwsys_stl::vector<kwsys_stl::string>::iterator ext
-            = extensions.begin(); ext != extensions.end(); ++ext)
+      tryPath = *p;
+      tryPath += name;
+      tryPath += *ext;
+      if(SystemTools::FileExists(tryPath.c_str()) &&
+          !SystemTools::FileIsDirectory(tryPath.c_str()))
         {
-        tryPath = *p;
-        tryPath += name;
-        tryPath += *ext;
-        if(SystemTools::FileExists(tryPath.c_str()) &&
-           !SystemTools::FileIsDirectory(tryPath.c_str()))
-          {
-          return SystemTools::CollapseFullPath(tryPath.c_str());
-          }
+        return SystemTools::CollapseFullPath(tryPath.c_str());
         }
       }
     // now try it without them
-- 
GitLab