]> granicus.if.org Git - clang/commitdiff
rearrange some code and make it more efficient.
authorChris Lattner <sabre@nondot.org>
Mon, 17 Dec 2007 05:59:27 +0000 (05:59 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 17 Dec 2007 05:59:27 +0000 (05:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45087 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/clang.cpp

index 76080f804df160abe1c0071e878c6e12d7d7c486..095eaaa6ca0a014cce8240111e897a79e95609e8 100644 (file)
@@ -616,24 +616,20 @@ static void AddPath(const std::string &Path, IncludeDirGroup Group,
                     bool isFramework, FileManager &FM) {
   assert(!Path.empty() && "can't handle empty path here");
   
-  const DirectoryEntry *DE;
-  if (Group == System) {
-    if (isysroot != "/")
-      DE = FM.getDirectory(isysroot + "/" + Path);
-    else if (Path[0] == '/')
-      DE = FM.getDirectory(Path);
-    else
-      DE = FM.getDirectory("/" + Path);
-  } else
-    DE = FM.getDirectory(Path);
+  // Compute the actual path, taking into consideration -isysroot.
+  llvm::SmallString<256> MappedPath;
   
-  if (DE == 0) {
-    if (Verbose)
-      fprintf(stderr, "ignoring nonexistent directory \"%s\"\n",
-              Path.c_str());
-    return;
+  // Handle isysroot.
+  if (Group == System) {
+    if (isysroot.size() != 1 || isysroot[0] != '/') // Add isysroot if present.
+      MappedPath.append(isysroot.begin(), isysroot.end());
+    if (Path[0] != '/')  // If in the system group, add a /.
+      MappedPath.push_back('/');
   }
   
+  MappedPath.append(Path.begin(), Path.end());
+
+  // Compute the DirectoryLookup type.
   DirectoryLookup::DirType Type;
   if (Group == Quoted || Group == Angled)
     Type = DirectoryLookup::NormalHeaderDir;
@@ -642,8 +638,18 @@ static void AddPath(const std::string &Path, IncludeDirGroup Group,
   else
     Type = DirectoryLookup::ExternCSystemHeaderDir;
   
-  IncludeGroup[Group].push_back(DirectoryLookup(DE, Type, isUserSupplied,
-                                                isFramework));
+  
+  // If the directory exists, add it.
+  if (const DirectoryEntry *DE = FM.getDirectory(&MappedPath[0], 
+                                                 &MappedPath[0]+
+                                                 MappedPath.size())) {
+    IncludeGroup[Group].push_back(DirectoryLookup(DE, Type, isUserSupplied,
+                                                  isFramework));
+    return;
+  }
+  
+  if (Verbose)
+    fprintf(stderr, "ignoring nonexistent directory \"%s\"\n", Path.c_str());
 }
 
 /// RemoveDuplicates - If there are duplicate directory entries in the specified