[llvm] 0ae9c65 - [tools] Use *Set::insert_range (NFC) (#133384)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 28 07:53:14 PDT 2025
Author: Kazu Hirata
Date: 2025-03-28T07:53:09-07:00
New Revision: 0ae9c65d4a1c8d1e620a2843f22e77f05fcf202f
URL: https://github.com/llvm/llvm-project/commit/0ae9c65d4a1c8d1e620a2843f22e77f05fcf202f
DIFF: https://github.com/llvm/llvm-project/commit/0ae9c65d4a1c8d1e620a2843f22e77f05fcf202f.diff
LOG: [tools] Use *Set::insert_range (NFC) (#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.
Added:
Modified:
llvm/tools/bugpoint/CrashDebugger.cpp
llvm/tools/llvm-lto/llvm-lto.cpp
llvm/tools/llvm-objdump/llvm-objdump.cpp
Removed:
################################################################################
diff --git a/llvm/tools/bugpoint/CrashDebugger.cpp b/llvm/tools/bugpoint/CrashDebugger.cpp
index 2268aac351789..a7777f778f66e 100644
--- a/llvm/tools/bugpoint/CrashDebugger.cpp
+++ b/llvm/tools/bugpoint/CrashDebugger.cpp
@@ -968,10 +968,7 @@ class ReduceCrashingNamedMDOps : public ListReducer<const MDNode *> {
bool ReduceCrashingNamedMDOps::TestNamedMDOps(
std::vector<const MDNode *> &NamedMDOps) {
// Convert list to set for fast lookup...
- SmallPtrSet<const MDNode *, 32> OldMDNodeOps;
- for (unsigned i = 0, e = NamedMDOps.size(); i != e; ++i) {
- OldMDNodeOps.insert(NamedMDOps[i]);
- }
+ SmallPtrSet<const MDNode *, 32> OldMDNodeOps(llvm::from_range, NamedMDOps);
outs() << "Checking for crash with only " << OldMDNodeOps.size();
if (OldMDNodeOps.size() == 1)
diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp
index 0aa47e534855c..bf2b5be977eb4 100644
--- a/llvm/tools/llvm-lto/llvm-lto.cpp
+++ b/llvm/tools/llvm-lto/llvm-lto.cpp
@@ -1090,9 +1090,7 @@ int main(int argc, char **argv) {
CodeGen.setTargetOptions(Options);
CodeGen.setShouldRestoreGlobalsLinkage(RestoreGlobalsLinkage);
- StringSet<MallocAllocator> DSOSymbolsSet;
- for (unsigned i = 0; i < DSOSymbols.size(); ++i)
- DSOSymbolsSet.insert(DSOSymbols[i]);
+ StringSet<MallocAllocator> DSOSymbolsSet(llvm::from_range, DSOSymbols);
std::vector<std::string> KeptDSOSyms;
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index c897881430fae..c62ebbae55885 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -2073,8 +2073,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
if (Start < SectionAddr || StopAddress <= Start)
continue;
- for (size_t i = 0; i < SymbolsHere.size(); ++i)
- FoundDisasmSymbolSet.insert(SymNamesHere[i]);
+ FoundDisasmSymbolSet.insert_range(SymNamesHere);
// The end is the section end, the beginning of the next symbol, or
// --stop-address.
More information about the llvm-commits
mailing list