summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Path.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2013-09-11 10:45:21 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2013-09-11 10:45:21 +0000
commitbd4ac9bc6d1e6773af47d7e078263e118ed8deb1 (patch)
tree41df86376966502f992600bb2d2d192a8024f931 /llvm/lib/Support/Path.cpp
parent607952bdadd541007954f449de76aeaa824ce3c7 (diff)
downloadbcm5719-llvm-bd4ac9bc6d1e6773af47d7e078263e118ed8deb1.tar.gz
bcm5719-llvm-bd4ac9bc6d1e6773af47d7e078263e118ed8deb1.zip
Path: Add an in-place version of path::native.
This reflects the common use case of nativizing a prepared path. The existing version invokes undefined behavior if input = output, add an assert to catch that case. llvm-svn: 190510
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r--llvm/lib/Support/Path.cpp23
1 files changed, 9 insertions, 14 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index 366fb849338..8d707aedded 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -449,23 +449,18 @@ void replace_extension(SmallVectorImpl<char> &path, const Twine &extension) {
}
void native(const Twine &path, SmallVectorImpl<char> &result) {
+ assert((!path.isSingleStringRef() ||
+ path.getSingleStringRef().data() != result.data()) &&
+ "path and result are not allowed to overlap!");
// Clear result.
result.clear();
-#ifdef LLVM_ON_WIN32
- SmallString<128> path_storage;
- StringRef p = path.toStringRef(path_storage);
- result.reserve(p.size());
- for (StringRef::const_iterator i = p.begin(),
- e = p.end();
- i != e;
- ++i) {
- if (*i == '/')
- result.push_back('\\');
- else
- result.push_back(*i);
- }
-#else
path.toVector(result);
+ native(result);
+}
+
+void native(SmallVectorImpl<char> &path) {
+#ifdef LLVM_ON_WIN32
+ std::replace(path.begin(), path.end(), '/', '\\');
#endif
}
OpenPOWER on IntegriCloud