Page MenuHomePhabricator

[NFC} Use const references to avoid copying objects in for-loops
Needs ReviewPublic

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
2073

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.