[cfe-commits] r39031 - in /cfe/cfe/trunk: Lex/HeaderSearch.cpp include/clang/Lex/HeaderSearch.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:26:59 PDT 2007
Author: sabre
Date: Wed Jul 11 11:26:58 2007
New Revision: 39031
URL: http://llvm.org/viewvc/llvm-project?rev=39031&view=rev
Log:
Implement framework filesystem caching.
Modified:
cfe/cfe/trunk/Lex/HeaderSearch.cpp
cfe/cfe/trunk/include/clang/Lex/HeaderSearch.h
Modified: cfe/cfe/trunk/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/HeaderSearch.cpp?rev=39031&r1=39030&r2=39031&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/HeaderSearch.cpp (original)
+++ cfe/cfe/trunk/Lex/HeaderSearch.cpp Wed Jul 11 11:26:58 2007
@@ -60,9 +60,13 @@
std::string::size_type SlashPos = Filename.find('/');
if (SlashPos == std::string::npos) return 0;
- // TODO: caching.
- ++NumFrameworkLookups;
+ const DirectoryEntry *&CacheLookup =
+ FrameworkMap[std::string(Filename.begin(), Filename.begin()+SlashPos)];
+ // If it is some other directory, fail.
+ if (CacheLookup && CacheLookup != Dir)
+ return 0;
+
// FrameworkName = "/System/Library/Frameworks/"
std::string FrameworkName = Dir->getName();
if (FrameworkName.empty() || FrameworkName[FrameworkName.size()-1] != '/')
@@ -73,6 +77,18 @@
// FrameworkName = "/System/Library/Frameworks/Cocoa.framework/"
FrameworkName += ".framework/";
+
+ if (CacheLookup == 0) {
+ ++NumFrameworkLookups;
+
+ // If the framework dir doesn't exist, we fail.
+ if (!sys::Path(FrameworkName).exists())
+ return 0;
+
+ // Otherwise, if it does, remember that this is the right direntry for this
+ // framework.
+ CacheLookup = Dir;
+ }
// Check "/System/Library/Frameworks/Cocoa.framework/Headers/file.h"
std::string HeadersFilename = FrameworkName + "Headers/" +
@@ -172,9 +188,6 @@
std::string::size_type SlashPos = Filename.find('/');
if (SlashPos == std::string::npos) return 0;
- // TODO: Cache subframework.
- ++NumSubFrameworkLookups;
-
// Look up the base framework name of the ContextFileEnt.
const std::string &ContextName = ContextFileEnt->getName();
std::string::size_type FrameworkPos = ContextName.find(".framework/");
@@ -184,11 +197,32 @@
std::string FrameworkName(ContextName.begin(),
ContextName.begin()+FrameworkPos+strlen(".framework/"));
+
// Append Frameworks/HIToolbox.framework/
FrameworkName += "Frameworks/";
FrameworkName += std::string(Filename.begin(), Filename.begin()+SlashPos);
FrameworkName += ".framework/";
+ const DirectoryEntry *&CacheLookup =
+ FrameworkMap[std::string(Filename.begin(), Filename.begin()+SlashPos)];
+
+ // Some other location?
+ if (CacheLookup && CacheLookup->getName() != FrameworkName)
+ return 0;
+
+ // Cache subframework.
+ if (CacheLookup == 0) {
+ ++NumSubFrameworkLookups;
+
+ // If the framework dir doesn't exist, we fail.
+ const DirectoryEntry *Dir = FileMgr.getDirectory(FrameworkName);
+ if (Dir == 0) return 0;
+
+ // Otherwise, if it does, remember that this is the right direntry for this
+ // framework.
+ CacheLookup = Dir;
+ }
+
const FileEntry *FE = 0;
// Check ".../Frameworks/HIToolbox.framework/Headers/HIToolbox.h"
Modified: cfe/cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=39031&r1=39030&r2=39031&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/HeaderSearch.h Wed Jul 11 11:26:58 2007
@@ -16,6 +16,7 @@
#include <vector>
#include <string>
+#include <map>
namespace llvm {
namespace clang {
@@ -116,7 +117,11 @@
/// that are included. The vector is indexed by the FileEntry's UID.
///
std::vector<PerFileInfo> FileInfo;
-
+
+ /// FrameworkMap - This is a collection mapping a framework or subframework
+ /// name like "Carbon" to the Carbon.framework directory.
+ std::map<std::string, const DirectoryEntry *> FrameworkMap;
+
// Various statistics we track for performance analysis.
unsigned NumIncluded;
unsigned NumMultiIncludeFileOptzn;
More information about the cfe-commits
mailing list