simplify logic, eliminate a copy of string data.

llvm-svn: 39086
This commit is contained in:
Chris Lattner 2006-10-30 04:34:28 +00:00
parent 2f4a89a5e8
commit 9c59bdace4
1 changed files with 7 additions and 8 deletions

View File

@ -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;