Skip to content

Commit 0ae9c65

Browse files
[tools] Use *Set::insert_range (NFC) (llvm#133384)
We can use *Set::insert_range to replace "for" loop-based insertions. In some cases, we can further fold insert_range into the set declaration.
1 parent 4382903 commit 0ae9c65

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

llvm/tools/bugpoint/CrashDebugger.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -968,10 +968,7 @@ class ReduceCrashingNamedMDOps : public ListReducer<const MDNode *> {
968968
bool ReduceCrashingNamedMDOps::TestNamedMDOps(
969969
std::vector<const MDNode *> &NamedMDOps) {
970970
// Convert list to set for fast lookup...
971-
SmallPtrSet<const MDNode *, 32> OldMDNodeOps;
972-
for (unsigned i = 0, e = NamedMDOps.size(); i != e; ++i) {
973-
OldMDNodeOps.insert(NamedMDOps[i]);
974-
}
971+
SmallPtrSet<const MDNode *, 32> OldMDNodeOps(llvm::from_range, NamedMDOps);
975972

976973
outs() << "Checking for crash with only " << OldMDNodeOps.size();
977974
if (OldMDNodeOps.size() == 1)

llvm/tools/llvm-lto/llvm-lto.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,9 +1090,7 @@ int main(int argc, char **argv) {
10901090
CodeGen.setTargetOptions(Options);
10911091
CodeGen.setShouldRestoreGlobalsLinkage(RestoreGlobalsLinkage);
10921092

1093-
StringSet<MallocAllocator> DSOSymbolsSet;
1094-
for (unsigned i = 0; i < DSOSymbols.size(); ++i)
1095-
DSOSymbolsSet.insert(DSOSymbols[i]);
1093+
StringSet<MallocAllocator> DSOSymbolsSet(llvm::from_range, DSOSymbols);
10961094

10971095
std::vector<std::string> KeptDSOSyms;
10981096

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,8 +2073,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
20732073
if (Start < SectionAddr || StopAddress <= Start)
20742074
continue;
20752075

2076-
for (size_t i = 0; i < SymbolsHere.size(); ++i)
2077-
FoundDisasmSymbolSet.insert(SymNamesHere[i]);
2076+
FoundDisasmSymbolSet.insert_range(SymNamesHere);
20782077

20792078
// The end is the section end, the beginning of the next symbol, or
20802079
// --stop-address.

0 commit comments

Comments
 (0)