-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[Clang][NFC] Avoid repeating copy of std::string in lambda implementation #153863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Clang][NFC] Avoid repeating copy of std::string in lambda implementation #153863
Conversation
…tion Static analysis flagged this code because it will cause unneeded copies of std::string. This fix is merely to use const auto & in the trailing return type.
@llvm/pr-subscribers-clang Author: Shafik Yaghmour (shafik) ChangesStatic analysis flagged this code because it will cause unneeded copies of std::string. This fix is merely to use const auto & in the trailing return type. Full diff: https://github.com/llvm/llvm-project/pull/153863.diff 1 Files Affected:
diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
index c3601a4e73e1f..81177a04654bb 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
@@ -205,7 +205,7 @@ class FullDependencyConsumer : public DependencyConsumer {
std::vector<P1689ModuleInfo> Requires) override {
ModuleName = Provided ? Provided->ModuleName : "";
llvm::transform(Requires, std::back_inserter(NamedModuleDeps),
- [](const auto &Module) { return Module.ModuleName; });
+ [](const auto &Module) -> const auto & { return Module.ModuleName; });
}
TranslationUnitDeps takeTranslationUnitDeps();
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
[](const auto &Module) { return Module.ModuleName; }); | ||
llvm::transform( | ||
Requires, std::back_inserter(NamedModuleDeps), | ||
[](const auto &Module) -> const auto & { return Module.ModuleName; }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ultimately, you're doing a copy either way: you're inserting a string into an std::vector<std::string>
. At best this saves a move constructor call.
Static analysis flagged this code because it will cause unneeded copies of std::string. This fix is merely to use const auto & in the trailing return type.