This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Use const references to avoid copying objects in for-loops
ClosedPublic

Authored by gAlfonso-bit on Dec 6 2022, 4:46 PM.

Diff Detail

Event Timeline

gAlfonso-bit created this revision.Dec 6 2022, 4:46 PM
Herald added a reviewer: ributzka. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
gAlfonso-bit requested review of this revision.Dec 6 2022, 4:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 6 2022, 4:46 PM

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.

llvm/lib/ObjCopy/ELF/ELFObject.cpp
2092

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).

llvm/tools/llvm-readobj/ObjDumper.h
55 ↗(On Diff #480753)

FWIW, I wouldn't normally pass around a std::function by reference.

gAlfonso-bit marked 2 inline comments as done.
gAlfonso-bit retitled this revision from [NFC} Use const references to avoid copying objects in for-loops to [NFC] Use const references to avoid copying objects in for-loops.Feb 16 2023, 8:24 AM

At least for enumerate, the loop variable change is unnecessary.

Removed changes to enumerate

This kind of blindly applying clang-tidy -checks='-*,performance-for-range-copy' --fix changes is easy for the contributor but is time consuming for reviewers.
Anyway, I have applied appropriated fixes to places where const auto & is not the best.

This revision was not accepted when it landed; it landed in state Needs Review.Sep 27 2023, 1:39 PM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.