r240545 - Express Driver::GetFilePath more concisely.

Douglas Katzman dougk at google.com
Wed Jun 24 08:10:30 PDT 2015


Author: dougk
Date: Wed Jun 24 10:10:30 2015
New Revision: 240545

URL: http://llvm.org/viewvc/llvm-project?rev=240545&view=rev
Log:
Express Driver::GetFilePath more concisely.

Modified:
    cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=240545&r1=240544&r2=240545&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Jun 24 10:10:30 2015
@@ -756,7 +756,7 @@ bool Driver::HandleImmediateArgs(const C
       llvm::outs() << ':';
       // Interpretation of leading '=' is needed only for NetBSD.
       if (Path[0] == '=')
-        llvm::outs() << sysroot << (Path.c_str() + 1);
+        llvm::outs() << sysroot << Path.substr(1);
       else
         llvm::outs() << Path;
     }
@@ -1835,14 +1835,10 @@ const char *Driver::GetNamedOutputPath(C
 std::string Driver::GetFilePath(const char *Name, const ToolChain &TC) const {
   // Respect a limited subset of the '-Bprefix' functionality in GCC by
   // attempting to use this prefix when looking for file paths.
-  for (Driver::prefix_list::const_iterator it = PrefixDirs.begin(),
-       ie = PrefixDirs.end(); it != ie; ++it) {
-    std::string Dir(*it);
+  for (const std::string &Dir : PrefixDirs) {
     if (Dir.empty())
       continue;
-    if (Dir[0] == '=')
-      Dir = SysRoot + Dir.substr(1);
-    SmallString<128> P(Dir);
+    SmallString<128> P(Dir[0] == '=' ? SysRoot + Dir.substr(1) : Dir);
     llvm::sys::path::append(P, Name);
     if (llvm::sys::fs::exists(Twine(P)))
       return P.str();
@@ -1853,15 +1849,10 @@ std::string Driver::GetFilePath(const ch
   if (llvm::sys::fs::exists(Twine(P)))
     return P.str();
 
-  const ToolChain::path_list &List = TC.getFilePaths();
-  for (ToolChain::path_list::const_iterator
-         it = List.begin(), ie = List.end(); it != ie; ++it) {
-    std::string Dir(*it);
+  for (const std::string &Dir : TC.getFilePaths()) {
     if (Dir.empty())
       continue;
-    if (Dir[0] == '=')
-      Dir = SysRoot + Dir.substr(1);
-    SmallString<128> P(Dir);
+    SmallString<128> P(Dir[0] == '=' ? SysRoot + Dir.substr(1) : Dir);
     llvm::sys::path::append(P, Name);
     if (llvm::sys::fs::exists(Twine(P)))
       return P.str();





More information about the cfe-commits mailing list