[cfe-commits] r45087 - /cfe/trunk/Driver/clang.cpp

Chris Lattner sabre at nondot.org
Sun Dec 16 21:59:27 PST 2007


Author: lattner
Date: Sun Dec 16 23:59:27 2007
New Revision: 45087

URL: http://llvm.org/viewvc/llvm-project?rev=45087&view=rev
Log:
rearrange some code and make it more efficient.

Modified:
    cfe/trunk/Driver/clang.cpp

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=45087&r1=45086&r2=45087&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Sun Dec 16 23:59:27 2007
@@ -616,24 +616,20 @@
                     bool isFramework, FileManager &FM) {
   assert(!Path.empty() && "can't handle empty path here");
   
-  const DirectoryEntry *DE;
+  // Compute the actual path, taking into consideration -isysroot.
+  llvm::SmallString<256> MappedPath;
+  
+  // Handle isysroot.
   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);
-  
-  if (DE == 0) {
-    if (Verbose)
-      fprintf(stderr, "ignoring nonexistent directory \"%s\"\n",
-              Path.c_str());
-    return;
+    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 @@
   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





More information about the cfe-commits mailing list