Wean LookupSubframeworkHeader off std::strings, use the new SmallString
class instead. SmallString allows to code to avoid hitting malloc in the normal case (or will, when some other stuff is converted over). llvm-svn: 39084
This commit is contained in:
parent
a85cbe28a0
commit
43fd42e4d9
|
@ -33,11 +33,10 @@ using namespace clang;
|
|||
/// getDirectory - Lookup, cache, and verify the specified directory. This
|
||||
/// returns null if the directory doesn't exist.
|
||||
///
|
||||
const DirectoryEntry *FileManager::getDirectory(const std::string &Filename) {
|
||||
const DirectoryEntry *FileManager::getDirectory(const char *FileStart,
|
||||
const char *FileEnd) {
|
||||
++NumDirLookups;
|
||||
|
||||
DirectoryEntry *&NamedDirEnt =
|
||||
DirEntries.GetOrCreateValue(&Filename[0], &Filename[0] + Filename.size());
|
||||
DirectoryEntry *&NamedDirEnt =DirEntries.GetOrCreateValue(FileStart, FileEnd);
|
||||
|
||||
// See if there is already an entry in the map.
|
||||
if (NamedDirEnt)
|
||||
|
@ -48,10 +47,14 @@ const DirectoryEntry *FileManager::getDirectory(const std::string &Filename) {
|
|||
// By default, initialize it to invalid.
|
||||
NamedDirEnt = NON_EXISTANT_DIR;
|
||||
|
||||
// Get the null-terminated directory name as stored as the key of the
|
||||
// DirEntries map.
|
||||
const char *InterndDirName = DirEntries.GetKeyForValueInMap(NamedDirEnt);
|
||||
|
||||
// Check to see if the directory exists.
|
||||
struct stat StatBuf;
|
||||
if (stat(Filename.c_str(), &StatBuf) || // Error stat'ing.
|
||||
!S_ISDIR(StatBuf.st_mode)) // Not a directory?
|
||||
if (stat(InterndDirName, &StatBuf) || // Error stat'ing.
|
||||
!S_ISDIR(StatBuf.st_mode)) // Not a directory?
|
||||
return 0;
|
||||
|
||||
// It exists. See if we have already opened a directory with the same inode.
|
||||
|
@ -64,7 +67,7 @@ const DirectoryEntry *FileManager::getDirectory(const std::string &Filename) {
|
|||
|
||||
// Otherwise, we don't have this directory yet, add it. We use the string
|
||||
// key from the DirEntries map as the string.
|
||||
UDE.Name = DirEntries.GetKeyForValueInMap(NamedDirEnt);
|
||||
UDE.Name = InterndDirName;
|
||||
return NamedDirEnt = &UDE;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "clang/Lex/HeaderSearch.h"
|
||||
#include "clang/Lex/IdentifierTable.h"
|
||||
#include "llvm/System/Path.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include <iostream>
|
||||
using namespace llvm;
|
||||
using namespace clang;
|
||||
|
@ -197,18 +198,19 @@ LookupSubframeworkHeader(const std::string &Filename,
|
|||
if (FrameworkPos == 0)
|
||||
return 0;
|
||||
|
||||
std::string FrameworkName(ContextName, FrameworkPos+strlen(".framework/"));
|
||||
SmallString<1024> FrameworkName(ContextName,
|
||||
FrameworkPos+strlen(".framework/"));
|
||||
|
||||
// Append Frameworks/HIToolbox.framework/
|
||||
FrameworkName += "Frameworks/";
|
||||
FrameworkName += std::string(Filename.begin(), Filename.begin()+SlashPos);
|
||||
FrameworkName.append(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)
|
||||
if (CacheLookup && strcmp(CacheLookup->getName(), FrameworkName.c_str()) != 0)
|
||||
return 0;
|
||||
|
||||
// Cache subframework.
|
||||
|
@ -216,7 +218,8 @@ LookupSubframeworkHeader(const std::string &Filename,
|
|||
++NumSubFrameworkLookups;
|
||||
|
||||
// If the framework dir doesn't exist, we fail.
|
||||
const DirectoryEntry *Dir = FileMgr.getDirectory(FrameworkName);
|
||||
const DirectoryEntry *Dir = FileMgr.getDirectory(FrameworkName.begin(),
|
||||
FrameworkName.end());
|
||||
if (Dir == 0) return 0;
|
||||
|
||||
// Otherwise, if it does, remember that this is the right direntry for this
|
||||
|
@ -227,14 +230,17 @@ LookupSubframeworkHeader(const std::string &Filename,
|
|||
const FileEntry *FE = 0;
|
||||
|
||||
// Check ".../Frameworks/HIToolbox.framework/Headers/HIToolbox.h"
|
||||
std::string HeadersFilename = FrameworkName + "Headers/" +
|
||||
std::string(Filename.begin()+SlashPos+1, Filename.end());
|
||||
if (!(FE = FileMgr.getFile(HeadersFilename))) {
|
||||
SmallString<1024> HeadersFilename(FrameworkName);
|
||||
HeadersFilename += "Headers/";
|
||||
HeadersFilename.append(Filename.begin()+SlashPos+1, Filename.end());
|
||||
if (!(FE = FileMgr.getFile(HeadersFilename.begin(),
|
||||
HeadersFilename.end()))) {
|
||||
|
||||
// Check ".../Frameworks/HIToolbox.framework/PrivateHeaders/HIToolbox.h"
|
||||
std::string PrivateHeadersFilename = FrameworkName + "PrivateHeaders/" +
|
||||
std::string(Filename.begin()+SlashPos+1, Filename.end());
|
||||
if (!(FE = FileMgr.getFile(PrivateHeadersFilename)))
|
||||
HeadersFilename = FrameworkName;
|
||||
HeadersFilename += "PrivateHeaders/";
|
||||
HeadersFilename.append(Filename.begin()+SlashPos+1, Filename.end());
|
||||
if (!(FE = FileMgr.getFile(HeadersFilename.begin(), HeadersFilename.end())))
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -90,12 +90,19 @@ public:
|
|||
/// getDirectory - Lookup, cache, and verify the specified directory. This
|
||||
/// returns null if the directory doesn't exist.
|
||||
///
|
||||
const DirectoryEntry *getDirectory(const std::string &Filename);
|
||||
const DirectoryEntry *getDirectory(const std::string &Filename) {
|
||||
return getDirectory(&Filename[0], &Filename[0] + Filename.size());
|
||||
}
|
||||
const DirectoryEntry *getDirectory(const char *FileStart,const char *FileEnd);
|
||||
|
||||
/// getFile - Lookup, cache, and verify the specified file. This returns null
|
||||
/// if the file doesn't exist.
|
||||
///
|
||||
const FileEntry *getFile(const std::string &Filename);
|
||||
const FileEntry *getFile(const char *FilenameStart,
|
||||
const char *FilenameEnd) {
|
||||
return getFile(std::string(FilenameStart, FilenameEnd));
|
||||
}
|
||||
|
||||
void PrintStats() const;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue