Skip to content

Commit 4cf9d1e

Browse files
committed
[lldb][NFC] Modernize for-loops in ModuleList
Reviewed By: mib Differential Revision: https://reviews.llvm.org/D112379
1 parent 85bcc1e commit 4cf9d1e

File tree

2 files changed

+44
-65
lines changed

2 files changed

+44
-65
lines changed

lldb/include/lldb/Core/ModuleList.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class ModuleList {
159159
/// ModulesDidLoad may be deferred when adding multiple Modules
160160
/// to the Target, but it must be called at the end,
161161
/// before resuming execution.
162-
bool AppendIfNeeded(const lldb::ModuleSP &module_sp, bool notify = true);
162+
bool AppendIfNeeded(const lldb::ModuleSP &new_module, bool notify = true);
163163

164164
void Append(const ModuleList &module_list);
165165

lldb/source/Core/ModuleList.cpp

+43-64
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,15 @@ void ModuleList::ReplaceEquivalent(
200200
}
201201
}
202202

203-
bool ModuleList::AppendIfNeeded(const ModuleSP &module_sp, bool notify) {
204-
if (module_sp) {
203+
bool ModuleList::AppendIfNeeded(const ModuleSP &new_module, bool notify) {
204+
if (new_module) {
205205
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
206-
collection::iterator pos, end = m_modules.end();
207-
for (pos = m_modules.begin(); pos != end; ++pos) {
208-
if (pos->get() == module_sp.get())
206+
for (const ModuleSP &module_sp : m_modules) {
207+
if (module_sp.get() == new_module.get())
209208
return false; // Already in the list
210209
}
211210
// Only push module_sp on the list if it wasn't already in there.
212-
Append(module_sp, notify);
211+
Append(new_module, notify);
213212
return true;
214213
}
215214
return false;
@@ -372,10 +371,10 @@ void ModuleList::FindFunctions(ConstString name,
372371
Module::LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
373372

374373
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
375-
collection::const_iterator pos, end = m_modules.end();
376-
for (pos = m_modules.begin(); pos != end; ++pos) {
377-
(*pos)->FindFunctions(lookup_info.GetLookupName(), CompilerDeclContext(),
378-
lookup_info.GetNameTypeMask(), options, sc_list);
374+
for (const ModuleSP &module_sp : m_modules) {
375+
module_sp->FindFunctions(lookup_info.GetLookupName(),
376+
CompilerDeclContext(),
377+
lookup_info.GetNameTypeMask(), options, sc_list);
379378
}
380379

381380
const size_t new_size = sc_list.GetSize();
@@ -384,10 +383,9 @@ void ModuleList::FindFunctions(ConstString name,
384383
lookup_info.Prune(sc_list, old_size);
385384
} else {
386385
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
387-
collection::const_iterator pos, end = m_modules.end();
388-
for (pos = m_modules.begin(); pos != end; ++pos) {
389-
(*pos)->FindFunctions(name, CompilerDeclContext(), name_type_mask,
390-
options, sc_list);
386+
for (const ModuleSP &module_sp : m_modules) {
387+
module_sp->FindFunctions(name, CompilerDeclContext(), name_type_mask,
388+
options, sc_list);
391389
}
392390
}
393391
}
@@ -401,10 +399,9 @@ void ModuleList::FindFunctionSymbols(ConstString name,
401399
Module::LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
402400

403401
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
404-
collection::const_iterator pos, end = m_modules.end();
405-
for (pos = m_modules.begin(); pos != end; ++pos) {
406-
(*pos)->FindFunctionSymbols(lookup_info.GetLookupName(),
407-
lookup_info.GetNameTypeMask(), sc_list);
402+
for (const ModuleSP &module_sp : m_modules) {
403+
module_sp->FindFunctionSymbols(lookup_info.GetLookupName(),
404+
lookup_info.GetNameTypeMask(), sc_list);
408405
}
409406

410407
const size_t new_size = sc_list.GetSize();
@@ -413,9 +410,8 @@ void ModuleList::FindFunctionSymbols(ConstString name,
413410
lookup_info.Prune(sc_list, old_size);
414411
} else {
415412
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
416-
collection::const_iterator pos, end = m_modules.end();
417-
for (pos = m_modules.begin(); pos != end; ++pos) {
418-
(*pos)->FindFunctionSymbols(name, name_type_mask, sc_list);
413+
for (const ModuleSP &module_sp : m_modules) {
414+
module_sp->FindFunctionSymbols(name, name_type_mask, sc_list);
419415
}
420416
}
421417
}
@@ -424,65 +420,54 @@ void ModuleList::FindFunctions(const RegularExpression &name,
424420
const ModuleFunctionSearchOptions &options,
425421
SymbolContextList &sc_list) {
426422
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
427-
collection::const_iterator pos, end = m_modules.end();
428-
for (pos = m_modules.begin(); pos != end; ++pos) {
429-
(*pos)->FindFunctions(name, options, sc_list);
430-
}
423+
for (const ModuleSP &module_sp : m_modules)
424+
module_sp->FindFunctions(name, options, sc_list);
431425
}
432426

433427
void ModuleList::FindCompileUnits(const FileSpec &path,
434428
SymbolContextList &sc_list) const {
435429
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
436-
collection::const_iterator pos, end = m_modules.end();
437-
for (pos = m_modules.begin(); pos != end; ++pos) {
438-
(*pos)->FindCompileUnits(path, sc_list);
439-
}
430+
for (const ModuleSP &module_sp : m_modules)
431+
module_sp->FindCompileUnits(path, sc_list);
440432
}
441433

442434
void ModuleList::FindGlobalVariables(ConstString name, size_t max_matches,
443435
VariableList &variable_list) const {
444436
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
445-
collection::const_iterator pos, end = m_modules.end();
446-
for (pos = m_modules.begin(); pos != end; ++pos) {
447-
(*pos)->FindGlobalVariables(name, CompilerDeclContext(), max_matches,
448-
variable_list);
437+
for (const ModuleSP &module_sp : m_modules) {
438+
module_sp->FindGlobalVariables(name, CompilerDeclContext(), max_matches,
439+
variable_list);
449440
}
450441
}
451442

452443
void ModuleList::FindGlobalVariables(const RegularExpression &regex,
453444
size_t max_matches,
454445
VariableList &variable_list) const {
455446
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
456-
collection::const_iterator pos, end = m_modules.end();
457-
for (pos = m_modules.begin(); pos != end; ++pos) {
458-
(*pos)->FindGlobalVariables(regex, max_matches, variable_list);
459-
}
447+
for (const ModuleSP &module_sp : m_modules)
448+
module_sp->FindGlobalVariables(regex, max_matches, variable_list);
460449
}
461450

462451
void ModuleList::FindSymbolsWithNameAndType(ConstString name,
463452
SymbolType symbol_type,
464453
SymbolContextList &sc_list) const {
465454
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
466-
collection::const_iterator pos, end = m_modules.end();
467-
for (pos = m_modules.begin(); pos != end; ++pos)
468-
(*pos)->FindSymbolsWithNameAndType(name, symbol_type, sc_list);
455+
for (const ModuleSP &module_sp : m_modules)
456+
module_sp->FindSymbolsWithNameAndType(name, symbol_type, sc_list);
469457
}
470458

471459
void ModuleList::FindSymbolsMatchingRegExAndType(
472460
const RegularExpression &regex, lldb::SymbolType symbol_type,
473461
SymbolContextList &sc_list) const {
474462
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
475-
collection::const_iterator pos, end = m_modules.end();
476-
for (pos = m_modules.begin(); pos != end; ++pos)
477-
(*pos)->FindSymbolsMatchingRegExAndType(regex, symbol_type, sc_list);
463+
for (const ModuleSP &module_sp : m_modules)
464+
module_sp->FindSymbolsMatchingRegExAndType(regex, symbol_type, sc_list);
478465
}
479466

480467
void ModuleList::FindModules(const ModuleSpec &module_spec,
481468
ModuleList &matching_module_list) const {
482469
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
483-
collection::const_iterator pos, end = m_modules.end();
484-
for (pos = m_modules.begin(); pos != end; ++pos) {
485-
ModuleSP module_sp(*pos);
470+
for (const ModuleSP &module_sp : m_modules) {
486471
if (module_sp->MatchesModuleSpec(module_spec))
487472
matching_module_list.Append(module_sp);
488473
}
@@ -558,9 +543,8 @@ void ModuleList::FindTypes(Module *search_first, ConstString name,
558543
bool ModuleList::FindSourceFile(const FileSpec &orig_spec,
559544
FileSpec &new_spec) const {
560545
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
561-
collection::const_iterator pos, end = m_modules.end();
562-
for (pos = m_modules.begin(); pos != end; ++pos) {
563-
if ((*pos)->FindSourceFile(orig_spec, new_spec))
546+
for (const ModuleSP &module_sp : m_modules) {
547+
if (module_sp->FindSourceFile(orig_spec, new_spec))
564548
return true;
565549
}
566550
return false;
@@ -572,10 +556,9 @@ void ModuleList::FindAddressesForLine(const lldb::TargetSP target_sp,
572556
std::vector<Address> &output_local,
573557
std::vector<Address> &output_extern) {
574558
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
575-
collection::const_iterator pos, end = m_modules.end();
576-
for (pos = m_modules.begin(); pos != end; ++pos) {
577-
(*pos)->FindAddressesForLine(target_sp, file, line, function, output_local,
578-
output_extern);
559+
for (const ModuleSP &module_sp : m_modules) {
560+
module_sp->FindAddressesForLine(target_sp, file, line, function,
561+
output_local, output_extern);
579562
}
580563
}
581564

@@ -602,10 +585,8 @@ size_t ModuleList::GetSize() const {
602585

603586
void ModuleList::Dump(Stream *s) const {
604587
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
605-
collection::const_iterator pos, end = m_modules.end();
606-
for (pos = m_modules.begin(); pos != end; ++pos) {
607-
(*pos)->Dump(s);
608-
}
588+
for (const ModuleSP &module_sp : m_modules)
589+
module_sp->Dump(s);
609590
}
610591

611592
void ModuleList::LogUUIDAndPaths(Log *log, const char *prefix_cstr) {
@@ -628,9 +609,8 @@ void ModuleList::LogUUIDAndPaths(Log *log, const char *prefix_cstr) {
628609
bool ModuleList::ResolveFileAddress(lldb::addr_t vm_addr,
629610
Address &so_addr) const {
630611
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
631-
collection::const_iterator pos, end = m_modules.end();
632-
for (pos = m_modules.begin(); pos != end; ++pos) {
633-
if ((*pos)->ResolveFileAddress(vm_addr, so_addr))
612+
for (const ModuleSP &module_sp : m_modules) {
613+
if (module_sp->ResolveFileAddress(vm_addr, so_addr))
634614
return true;
635615
}
636616

@@ -673,10 +653,9 @@ uint32_t ModuleList::ResolveSymbolContextsForFileSpec(
673653
const FileSpec &file_spec, uint32_t line, bool check_inlines,
674654
SymbolContextItem resolve_scope, SymbolContextList &sc_list) const {
675655
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
676-
collection::const_iterator pos, end = m_modules.end();
677-
for (pos = m_modules.begin(); pos != end; ++pos) {
678-
(*pos)->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
679-
resolve_scope, sc_list);
656+
for (const ModuleSP &module_sp : m_modules) {
657+
module_sp->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
658+
resolve_scope, sc_list);
680659
}
681660

682661
return sc_list.GetSize();

0 commit comments

Comments
 (0)