[cfe-commits] r39084 - in /cfe/cfe/trunk: Basic/FileManager.cpp Lex/HeaderSearch.cpp include/clang/Basic/FileManager.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:27:24 PDT 2007
Author: sabre
Date: Wed Jul 11 11:27:23 2007
New Revision: 39084
URL: http://llvm.org/viewvc/llvm-project?rev=39084&view=rev
Log:
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).
Modified:
cfe/cfe/trunk/Basic/FileManager.cpp
cfe/cfe/trunk/Lex/HeaderSearch.cpp
cfe/cfe/trunk/include/clang/Basic/FileManager.h
Modified: cfe/cfe/trunk/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Basic/FileManager.cpp?rev=39084&r1=39083&r2=39084&view=diff
==============================================================================
--- cfe/cfe/trunk/Basic/FileManager.cpp (original)
+++ cfe/cfe/trunk/Basic/FileManager.cpp Wed Jul 11 11:27:23 2007
@@ -33,11 +33,10 @@
/// 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 @@
// 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 @@
// 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;
}
Modified: cfe/cfe/trunk/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/HeaderSearch.cpp?rev=39084&r1=39083&r2=39084&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/HeaderSearch.cpp (original)
+++ cfe/cfe/trunk/Lex/HeaderSearch.cpp Wed Jul 11 11:27:23 2007
@@ -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 @@
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 @@
++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 @@
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;
}
Modified: cfe/cfe/trunk/include/clang/Basic/FileManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/FileManager.h?rev=39084&r1=39083&r2=39084&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/cfe/trunk/include/clang/Basic/FileManager.h Wed Jul 11 11:27:23 2007
@@ -90,12 +90,19 @@
/// 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;
};
More information about the cfe-commits
mailing list