diff --git a/include/llvm/Support/Path.h b/include/llvm/Support/Path.h index f9a65e533a9..b2afe1b8e8a 100644 --- a/include/llvm/Support/Path.h +++ b/include/llvm/Support/Path.h @@ -173,6 +173,13 @@ void append(SmallVectorImpl &path, /// @param result Holds the result of the transformation. void native(const Twine &path, SmallVectorImpl &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 &path); + /// @} /// @name Lexical Observers /// @{ diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index 366fb849338..8d707aedded 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -449,23 +449,18 @@ void replace_extension(SmallVectorImpl &path, const Twine &extension) { } void native(const Twine &path, SmallVectorImpl &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 &path) { +#ifdef LLVM_ON_WIN32 + std::replace(path.begin(), path.end(), '/', '\\'); #endif }