[llvm] r190510 - Path: Add an in-place version of path::native.
Benjamin Kramer
benny.kra at googlemail.com
Wed Sep 11 03:45:21 PDT 2013
Author: d0k
Date: Wed Sep 11 05:45:21 2013
New Revision: 190510
URL: http://llvm.org/viewvc/llvm-project?rev=190510&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/Support/Path.h
llvm/trunk/lib/Support/Path.cpp
Modified: llvm/trunk/include/llvm/Support/Path.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Path.h?rev=190510&r1=190509&r2=190510&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Path.h (original)
+++ llvm/trunk/include/llvm/Support/Path.h Wed Sep 11 05:45:21 2013
@@ -173,6 +173,13 @@ void append(SmallVectorImpl<char> &path,
/// @param result Holds the result of the transformation.
void native(const Twine &path, SmallVectorImpl<char> &result);
+/// Convert path to the native form in place. This is used to give paths to
+/// users and operating system calls in the platform's normal way. For example,
+/// on Windows all '/' are converted to '\'.
+///
+/// @param path A path that is transformed to native format.
+void native(SmallVectorImpl<char> &path);
+
/// @}
/// @name Lexical Observers
/// @{
Modified: llvm/trunk/lib/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Path.cpp?rev=190510&r1=190509&r2=190510&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Path.cpp (original)
+++ llvm/trunk/lib/Support/Path.cpp Wed Sep 11 05:45:21 2013
@@ -449,23 +449,18 @@ void replace_extension(SmallVectorImpl<c
}
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
}
More information about the llvm-commits
mailing list