[clang] [clang] Specialize invocation path visitation to the cow (PR #205686)
Ben Langmuir via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 26 08:16:43 PDT 2026
================
@@ -5354,108 +5354,87 @@ std::string CompilerInvocation::computeContextHash() const {
return toString(llvm::APInt(64, Hash), 36, /*Signed=*/false);
}
-void CompilerInvocationBase::visitPathsImpl(
- llvm::function_ref<bool(std::string &)> Predicate) {
-#define RETURN_IF(PATH) \
+void CowCompilerInvocation::visitMutPaths(
+ llvm::function_ref<VisitMutResult(StringRef, std::string &)> Cb) {
+ std::string NewValue;
+
+#define RETURN_IF(OPTS, PATH) \
do { \
- if (Predicate(PATH)) \
+ VisitMutResult Res = Cb(PATH, NewValue); \
+ if (Res.Replace) { \
+ (void)ensureOwned(OPTS); \
+ PATH = ""; \
----------------
benlangmuir wrote:
This is very minor, but `.clear()` optimizes better than assignment to empty string. Despite the compiler being able to detect the string has length 0 it still ends up calling out to library functions.
https://github.com/llvm/llvm-project/pull/205686
More information about the cfe-commits
mailing list