summaryrefslogtreecommitdiff
path: root/lib/System/Path.cpp
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@google.com>2009-12-17 21:02:39 +0000
committerJeffrey Yasskin <jyasskin@google.com>2009-12-17 21:02:39 +0000
commit88cd3582b6cb70c0283e4c5d6d783114323a1ce1 (patch)
tree7debf4e6f69213f00f713215844f951a4f087b07 /lib/System/Path.cpp
parentaeb79aea8f4761f1c46731ac6bd58cbccdcfa097 (diff)
downloadllvm-88cd3582b6cb70c0283e4c5d6d783114323a1ce1.tar.gz
llvm-88cd3582b6cb70c0283e4c5d6d783114323a1ce1.tar.bz2
llvm-88cd3582b6cb70c0283e4c5d6d783114323a1ce1.tar.xz
Make Path use StringRef instead of std::string where possible.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91620 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Path.cpp')
-rw-r--r--lib/System/Path.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/lib/System/Path.cpp b/lib/System/Path.cpp
index 8e1fa538b7..6844530ce9 100644
--- a/lib/System/Path.cpp
+++ b/lib/System/Path.cpp
@@ -176,7 +176,7 @@ Path::FindLibrary(std::string& name) {
return sys::Path();
}
-std::string Path::GetDLLSuffix() {
+StringRef Path::GetDLLSuffix() {
return LTDL_SHLIB_EXT;
}
@@ -191,7 +191,7 @@ Path::isBitcodeFile() const {
return FT == Bitcode_FileType;
}
-bool Path::hasMagicNumber(const std::string &Magic) const {
+bool Path::hasMagicNumber(StringRef Magic) const {
std::string actualMagic;
if (getMagicNumber(actualMagic, static_cast<unsigned>(Magic.size())))
return Magic == actualMagic;
@@ -217,8 +217,9 @@ static void getPathList(const char*path, std::vector<Path>& Paths) {
Paths.push_back(tmpPath);
}
-static std::string getDirnameCharSep(const std::string& path, char Sep) {
-
+static StringRef getDirnameCharSep(StringRef path, const char *Sep) {
+ assert(Sep[0] != '\0' && Sep[1] == '\0' &&
+ "Sep must be a 1-character string literal.");
if (path.empty())
return ".";
@@ -227,31 +228,31 @@ static std::string getDirnameCharSep(const std::string& path, char Sep) {
signed pos = static_cast<signed>(path.size()) - 1;
- while (pos >= 0 && path[pos] == Sep)
+ while (pos >= 0 && path[pos] == Sep[0])
--pos;
if (pos < 0)
- return path[0] == Sep ? std::string(1, Sep) : std::string(".");
+ return path[0] == Sep[0] ? Sep : ".";
// Any slashes left?
signed i = 0;
- while (i < pos && path[i] != Sep)
+ while (i < pos && path[i] != Sep[0])
++i;
if (i == pos) // No slashes? Return "."
return ".";
// There is at least one slash left. Remove all trailing non-slashes.
- while (pos >= 0 && path[pos] != Sep)
+ while (pos >= 0 && path[pos] != Sep[0])
--pos;
// Remove any trailing slashes.
- while (pos >= 0 && path[pos] == Sep)
+ while (pos >= 0 && path[pos] == Sep[0])
--pos;
if (pos < 0)
- return path[0] == Sep ? std::string(1, Sep) : std::string(".");
+ return path[0] == Sep[0] ? Sep : ".";
return path.substr(0, pos+1);
}