[PATCH] D139487: [NFC} Use const references to avoid copying objects in for-loops
James Henderson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 7 00:27:56 PST 2022
jhenderson added a comment.
I'm not particularly familiar with much of this code, but it seems to me likely that it's not always the case that you should use `const &` for several of these, no more than you would if you were passing them in as function parameters. Unfortunately, the use of `auto` (often in violation of my undersetanding of the LLVM coding standards on `auto` usage) makes it hard to tell what the situation is.
================
Comment at: llvm/lib/ObjCopy/ELF/ELFObject.cpp:2073
- for (auto it : Obj.getUpdatedSections()) {
+ for (const auto &it : Obj.getUpdatedSections()) {
SectionBase *Sec = it.first;
----------------
This is probably unnecessary, though it can't hurt: it's a std::pair of two things that are designed to be passed by value, so hardly costly to copy (and will likely be a no-op change in optimized builds, at a guess).
================
Comment at: llvm/tools/llvm-readobj/ObjDumper.h:55
bool operator()(object::SymbolRef LHS, object::SymbolRef RHS) {
- for (CompPredicate Pred : Predicates) {
+ for (const CompPredicate &Pred : Predicates) {
if (Pred(LHS, RHS))
----------------
FWIW, I wouldn't normally pass around a std::function by reference.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139487/new/
https://reviews.llvm.org/D139487
More information about the llvm-commits
mailing list