[llvm] [tools] Use *Set::insert_range (NFC) (PR #133384)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 27 23:53:02 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-binary-utilities
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/133384.diff
3 Files Affected:
- (modified) llvm/tools/bugpoint/CrashDebugger.cpp (+1-4)
- (modified) llvm/tools/llvm-lto/llvm-lto.cpp (+1-3)
- (modified) llvm/tools/llvm-objdump/llvm-objdump.cpp (+1-2)
``````````diff
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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/133384
More information about the llvm-commits
mailing list