From 9c59bdace484e42b2f4e59f271b3fa464bf47b8f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 30 Oct 2006 04:34:28 +0000 Subject: [PATCH] simplify logic, eliminate a copy of string data. llvm-svn: 39086 --- clang/Basic/FileManager.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/clang/Basic/FileManager.cpp b/clang/Basic/FileManager.cpp index 6ae0031ba9bf..3ca9c8cbde8f 100644 --- a/clang/Basic/FileManager.cpp +++ b/clang/Basic/FileManager.cpp @@ -95,24 +95,23 @@ const FileEntry *FileManager::getFile(const char *NameStart, // By default, initialize it to invalid. NamedFileEnt = NON_EXISTANT_FILE; - // Figure out what directory it is in. - SmallString<1024> DirName; - - // If the string contains a / in it, strip off everything after it. + // Figure out what directory it is in. If the string contains a / in it, + // strip off everything after it. // FIXME: this logic should be in sys::Path. const char *SlashPos = NameEnd-1; while (SlashPos >= NameStart && SlashPos[0] != '/') --SlashPos; + const DirectoryEntry *DirInfo; if (SlashPos < NameStart) { // Use the current directory if file has no path component. - DirName.push_back('.'); + const char *Name = "."; + DirInfo = getDirectory(Name, Name+1); } else if (SlashPos == NameEnd-1) return 0; // If filename ends with a /, it's a directory. else - DirName.append(NameStart, SlashPos); - - const DirectoryEntry *DirInfo = getDirectory(DirName.begin(), DirName.end()); + DirInfo = getDirectory(NameStart, SlashPos); + if (DirInfo == 0) // Directory doesn't exist, file can't exist. return 0;