[llvm] 2a4b153 - [Support] [Path] Use std::replace instead of an explicit comparison loop. NFC.
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 13 12:56:07 PDT 2021
Author: Martin Storsjö
Date: 2021-10-13T22:55:14+03:00
New Revision: 2a4b1539e991f289ea62f74a03f3fc6aa49c9c1f
URL: https://github.com/llvm/llvm-project/commit/2a4b1539e991f289ea62f74a03f3fc6aa49c9c1f
DIFF: https://github.com/llvm/llvm-project/commit/2a4b1539e991f289ea62f74a03f3fc6aa49c9c1f.diff
LOG: [Support] [Path] Use std::replace instead of an explicit comparison loop. NFC.
After 8fc7a907b93a8e9eef96e872f8f926db3ebfe9b6, this loop does
the same as a plain `std::replace`.
Also clarify the comment about what this function does.
Differential Revision: https://reviews.llvm.org/D111730
Added:
Modified:
llvm/include/llvm/Support/Path.h
llvm/lib/Support/Path.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/Path.h b/llvm/include/llvm/Support/Path.h
index af70e086a1b64..54e0ff0a9000b 100644
--- a/llvm/include/llvm/Support/Path.h
+++ b/llvm/include/llvm/Support/Path.h
@@ -212,7 +212,7 @@ void append(SmallVectorImpl<char> &path, const_iterator begin,
/// Convert path to the native form. 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 '\'.
+/// all '/' are converted to '\'. On Unix, it converts all '\' to '/'.
///
/// @param path A path that is transformed to native format.
/// @param result Holds the result of the transformation.
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index a724ba2faf93a..f770bcc548139 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -557,9 +557,7 @@ void native(SmallVectorImpl<char> &Path, Style style) {
Path = PathHome;
}
} else {
- for (auto PI = Path.begin(), PE = Path.end(); PI < PE; ++PI)
- if (*PI == '\\')
- *PI = '/';
+ std::replace(Path.begin(), Path.end(), '\\', '/');
}
}
More information about the llvm-commits
mailing list