diff --git a/clang/Basic/FileManager.cpp b/clang/Basic/FileManager.cpp index c1520c80e447..5ee032ef0332 100644 --- a/clang/Basic/FileManager.cpp +++ b/clang/Basic/FileManager.cpp @@ -59,11 +59,12 @@ const DirectoryEntry *FileManager::getDirectory(const std::string &Filename) { DirectoryEntry &UDE = UniqueDirs[std::make_pair(StatBuf.st_dev, StatBuf.st_ino)]; - if (UDE.getName()[0]) // Already have an entry with this inode, return it. + if (UDE.getName()) // Already have an entry with this inode, return it. return NamedDirEnt = &UDE; - // Otherwise, we don't have this directory yet, add it. - UDE.Name = 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); return NamedDirEnt = &UDE; } diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index 0d0bd33aeef1..dd57e3bf5262 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -27,11 +27,11 @@ class FileManager; /// DirectoryEntry - Cached information about one directory on the disk. /// class DirectoryEntry { - std::string Name; // Name of the directory. + const char *Name; // Name of the directory. friend class FileManager; public: - DirectoryEntry() {} - const char *getName() const { return Name.c_str(); } + DirectoryEntry() : Name(0) {} + const char *getName() const { return Name; } }; /// FileEntry - Cached information about one file on the disk.