aboutsummaryrefslogtreecommitdiff
path: root/lib/Basic/FileManager.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2010-11-21 11:32:22 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2010-11-21 11:32:22 +0000
commitaa8b2d95bc108e8f3a443e4a936e1ed8a3cc1cc6 (patch)
tree97f9a8dcd3167bb71b95b543e33d74138b6097c7 /lib/Basic/FileManager.cpp
parent6538227d51df249b07c8ab80ae376f5c1d14403c (diff)
Filename.rfind("/\\") won't give us the position of the last directory seperator.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119939 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/FileManager.cpp')
-rw-r--r--lib/Basic/FileManager.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/Basic/FileManager.cpp b/lib/Basic/FileManager.cpp
index 16a182d7af..c8a71f64ea 100644
--- a/lib/Basic/FileManager.cpp
+++ b/lib/Basic/FileManager.cpp
@@ -47,7 +47,7 @@ using namespace clang;
#ifdef LLVM_ON_WIN32
-#define DIR_SEPARATOR_CHARS "/\\"
+#define IS_DIR_SEPARATOR_CHAR(x) ((x) == '/' || (x) == '\\')
namespace {
static std::string GetFullPath(const char *relPath) {
@@ -104,7 +104,7 @@ public:
#else
-#define DIR_SEPARATOR_CHARS "/"
+#define IS_DIR_SEPARATOR_CHAR(x) ((x) == '/')
class FileManager::UniqueDirContainer {
/// UniqueDirs - Cache from ID's to existing directories/files.
@@ -203,20 +203,21 @@ static const DirectoryEntry *getDirectoryFromFile(FileManager &FileMgr,
// 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.
- size_t SlashPos = Filename.rfind(DIR_SEPARATOR_CHARS);
-
+ size_t SlashPos = Filename.size();
+ while (SlashPos != 0 && !IS_DIR_SEPARATOR_CHAR(Filename[SlashPos-1]))
+ --SlashPos;
+
// Use the current directory if file has no path component.
- if (SlashPos == llvm::StringRef::npos)
+ if (SlashPos == 0)
return FileMgr.getDirectory(".", FileSystemOpts);
if (SlashPos == Filename.size()-1)
return 0; // If filename ends with a /, it's a directory.
-
+
// Ignore repeated //'s.
- while (SlashPos != 0 &&
- llvm::StringRef(DIR_SEPARATOR_CHARS).count(Filename[SlashPos-1]))
+ while (SlashPos != 0 && IS_DIR_SEPARATOR_CHAR(Filename[SlashPos-1]))
--SlashPos;
-
+
return FileMgr.getDirectory(Filename.substr(0, SlashPos), FileSystemOpts);
}
@@ -226,8 +227,7 @@ static const DirectoryEntry *getDirectoryFromFile(FileManager &FileMgr,
const DirectoryEntry *FileManager::getDirectory(llvm::StringRef Filename,
const FileSystemOptions &FileSystemOpts) {
// stat doesn't like trailing separators (at least on Windows).
- if (Filename.size() > 1 &&
- (Filename.back() == '/' || Filename.back() == '\\'))
+ if (Filename.size() > 1 && IS_DIR_SEPARATOR_CHAR(Filename.back()))
Filename = Filename.substr(0, Filename.size()-1);
++NumDirLookups;