Skip to content

Commit

Permalink
Replace for loops with std::list::const_iterator into equivalent for-…
Browse files Browse the repository at this point in the history
…each loop in libs/

Regex substitutions have to be run in the following order:
for[ \t\n]*\([ \t\n]*(?:typename )?[ \t\n]*(?:std::)?list<[ \t\n]*(?:typename )?[ \t\n]*(?:struct )?[ \t\n]*(.*)[ \t\n]*\*[ \t\n]*>::const_iterator[ \t\n]+(.*)[ \t\n]*=[ \t\n]*(.*)\.begin[ \t\n]*\(\);[ \t\n]*\2[ \t\n]*(?:<|!=)[ \t\n]*\3\.end[ \t\n]*\(\);[ \t\n]*(?:\+\+\2|\2\+\+)\)[ \t\n]*\{ -> for (\1* const& \2 : \3) {
for[ \t\n]*\([ \t\n]*(?:typename )?[ \t\n]*(?:std::)?list<[ \t\n]*(?:typename )?[ \t\n]*(?:struct )?[ \t\n]*(.*)[ \t\n]*>::const_iterator[ \t\n]+(.*)[ \t\n]*=[ \t\n]*(.*)\.begin[ \t\n]*\(\);[ \t\n]*\2[ \t\n]*(?:<|!=)[ \t\n]*\3\.end[ \t\n]*\(\);[ \t\n]*(?:\+\+\2|\2\+\+)\)[ \t\n]*\{ -> for (const \1& \2 : \3) {
for[ \t\n]*\([ \t\n]*(?:typename )?[ \t\n]*(?:std::)?list<[ \t\n]*(?:typename )?[ \t\n]*(?:struct )?[ \t\n]*(.*)[ \t\n]*\*[ \t\n]*>::const_iterator[ \t\n]+(.*)[ \t\n]*=[ \t\n]*(.*)->begin[ \t\n]*\(\);[ \t\n]*\2[ \t\n]*(?:<|!=)[ \t\n]*\3->end[ \t\n]*\(\);[ \t\n]*(?:\+\+\2|\2\+\+)\)[ \t\n]*\{ -> for (\1* const& \2 : *\3) {
for[ \t\n]*\([ \t\n]*(?:typename )?[ \t\n]*(?:std::)?list<[ \t\n]*(?:typename )?[ \t\n]*(?:struct )?[ \t\n]*(.*)[ \t\n]*>::const_iterator[ \t\n]+(.*)[ \t\n]*=[ \t\n]*(.*)->begin[ \t\n]*\(\);[ \t\n]*\2[ \t\n]*(?:<|!=)[ \t\n]*\3->end[ \t\n]*\(\);[ \t\n]*(?:\+\+\2|\2\+\+)\)[ \t\n]*\{ -> for (const \1& \2 : *\3) {
for[ \t\n]*\([ \t\n]*(?:typename )?[ \t\n]*(?:std::)?list<[ \t\n]*(?:typename )?[ \t\n]*(?:struct )?[ \t\n]*(.*)[ \t\n]*\*[ \t\n]*>::const_iterator[ \t\n]+(.*)[ \t\n]*=[ \t\n]*begin[ \t\n]*\(\);[ \t\n]*\2[ \t\n]*(?:<|!=)[ \t\n]*end[ \t\n]*\(\);[ \t\n]*(?:\+\+\2|\2\+\+)\)[ \t\n]*\{ -> for (\1* const& \2 : *this) {
for[ \t\n]*\([ \t\n]*(?:typename )?[ \t\n]*(?:std::)?list<[ \t\n]*(?:typename )?[ \t\n]*(?:struct )?[ \t\n]*(.*)[ \t\n]*>::const_iterator[ \t\n]+(.*)[ \t\n]*=[ \t\n]*begin[ \t\n]*\(\);[ \t\n]*\2[ \t\n]*(?:<|!=)[ \t\n]*end[ \t\n]*\(\);[ \t\n]*(?:\+\+\2|\2\+\+)\)[ \t\n]*\{ -> for (const \1& \2 : this) {

Any dereferencing of the loop internal variable has to be removed manually.
  • Loading branch information
aledomu committed Nov 21, 2024
1 parent 014ad8b commit 22a9b49
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 120 deletions.
10 changes: 5 additions & 5 deletions libs/ardour/analysis_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,22 @@ AnalysisGraph::analyze_range (std::shared_ptr<Route> route, std::shared_ptr<Audi
}
const samplecnt_t n_samples = _max_chunksize - (_max_chunksize % n_audio);

for (std::list<TimelineRange>::const_iterator j = range.begin(); j != range.end(); ++j) {
for (const TimelineRange& j : range) {

interleaver.reset (new Interleaver<Sample> ());
interleaver->init (n_audio, _max_chunksize);

chunker.reset (new Chunker<Sample> (n_samples));
analyser.reset (new Analyser (
_session->nominal_sample_rate(),
n_audio, n_samples, (*j).length_samples()));
n_audio, n_samples, j.length_samples()));

interleaver->add_output(chunker);
chunker->add_output (analyser);

samplecnt_t x = 0;
const samplecnt_t rlen = j->length().samples();
const samplepos_t rpos = j->start().samples();
const samplecnt_t rlen = j.length().samples();
const samplepos_t rpos = j.start().samples();

while (x < rlen) {
samplecnt_t chunk = std::min (_max_chunksize, rlen - x);
Expand Down Expand Up @@ -175,7 +175,7 @@ AnalysisGraph::analyze_range (std::shared_ptr<Route> route, std::shared_ptr<Audi
_session->nominal_sample_rate(),
100, false),
Timecode::timecode_format_sampletime (
(*j).end().samples(),
j.end().samples(),
_session->nominal_sample_rate(),
100, false)
);
Expand Down
19 changes: 9 additions & 10 deletions libs/ardour/control_protocol_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -583,21 +583,20 @@ ControlProtocolManager::get_state () const
XMLNode* root = new XMLNode (state_node_name);
Glib::Threads::RWLock::ReaderLock lm (protocols_lock);

for (list<ControlProtocolInfo*>::const_iterator i = control_protocol_info.begin(); i != control_protocol_info.end(); ++i) {

if ((*i)->protocol) {
XMLNode& child_state ((*i)->protocol->get_state());
child_state.set_property (X_("active"), !(*i)->automatic);
delete ((*i)->state);
(*i)->state = new XMLNode (child_state);
for (ControlProtocolInfo* const& i : control_protocol_info) {
if (i->protocol) {
XMLNode& child_state (i->protocol->get_state());
child_state.set_property (X_("active"), !i->automatic);
delete (i->state);
i->state = new XMLNode (child_state);
root->add_child_nocopy (child_state);
} else if ((*i)->state) {
XMLNode* child_state = new XMLNode (*(*i)->state);
} else if (i->state) {
XMLNode* child_state = new XMLNode (*i->state);
child_state->set_property (X_("active"), false);
root->add_child_nocopy (*child_state);
} else {
XMLNode* child_state = new XMLNode (X_("Protocol"));
child_state->set_property (X_("name"), (*i)->name);
child_state->set_property (X_("name"), i->name);
child_state->set_property (X_("active"), false);
root->add_child_nocopy (*child_state);
}
Expand Down
4 changes: 2 additions & 2 deletions libs/ardour/export_graph_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ unsigned
ExportGraphBuilder::get_postprocessing_cycle_count() const
{
unsigned max = 0;
for (std::list<Intermediate *>::const_iterator it = intermediates.begin(); it != intermediates.end(); ++it) {
max = std::max(max, (*it)->get_postprocessing_cycle_count());
for (Intermediate * const& it : intermediates) {
max = std::max(max, it->get_postprocessing_cycle_count());
}
return max;
}
Expand Down
4 changes: 1 addition & 3 deletions libs/ardour/export_profile_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1004,9 +1004,7 @@ ExportProfileManager::check_config (std::shared_ptr<Warnings> warnings,
std::list<string> paths;
build_filenames (paths, filename, timespans, channel_config, format);

for (std::list<string>::const_iterator path_it = paths.begin (); path_it != paths.end (); ++path_it) {
string path = *path_it;

for (const string& path : paths) {
if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
warnings->conflicting_filenames.push_back (path);
}
Expand Down
14 changes: 7 additions & 7 deletions libs/ardour/monitor_port.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,22 +236,22 @@ MonitorPort::set_active_monitors (std::list<std::string> const& pl)
removals.push_back (i->first);
}
/* add ports */
for (std::list<std::string>::const_iterator i = pl.begin (); i != pl.end (); ++i) {
std::pair<MonitorPorts::iterator, bool> it = mp->insert (make_pair (*i, std::shared_ptr<MonitorInfo> (new MonitorInfo ())));
for (const std::string& i : pl) {
std::pair<MonitorPorts::iterator, bool> it = mp->insert (make_pair (i, std::shared_ptr<MonitorInfo> (new MonitorInfo ())));
if (!it.second && !it.first->second->remove) {
/* already present */
continue;
}
it.first->second->remove = false;
additions.push_back (*i);
additions.push_back (i);
}
}

for (std::list<std::string>::const_iterator i = removals.begin (); i != removals.end (); ++i) {
MonitorInputChanged (*i, false); /* EMIT SIGNAL */
for (const std::string& i : removals) {
MonitorInputChanged (i, false); /* EMIT SIGNAL */
}
for (std::list<std::string>::const_iterator i = additions.begin (); i != additions.end (); ++i) {
MonitorInputChanged (*i, true); /* EMIT SIGNAL */
for (const std::string& i : additions) {
MonitorInputChanged (i, true); /* EMIT SIGNAL */
}
if (!removals.empty () || !additions.empty ()) {
AudioEngine::instance()->session ()->SoloChanged (); /* EMIT SIGNAL */
Expand Down
14 changes: 6 additions & 8 deletions libs/ardour/panner_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,11 @@ PannerManager::select_panner (ChanCount in, ChanCount out, std::string const uri
PannerInfo*
PannerManager::get_by_uri (std::string uri) const
{
PannerInfo* pi = NULL;
for (list<PannerInfo*>::const_iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
if ((*p)->descriptor.panner_uri != uri) continue;
pi = (*p);
break;
for (PannerInfo* const& pi : panner_info) {
if (pi->descriptor.panner_uri != uri) continue;
return pi;
}
return pi;
return nullptr;
}

PannerUriMap
Expand All @@ -279,8 +277,8 @@ PannerManager::get_available_panners(uint32_t const a_in, uint32_t const a_out)
}

/* get available panners for current configuration. */
for (list<PannerInfo*>::const_iterator p = panner_info.begin(); p != panner_info.end(); ++p) {
PanPluginDescriptor const& d ((*p)->descriptor);
for (PannerInfo* const& p : panner_info) {
PanPluginDescriptor const& d (p->descriptor);
if (d.in != -1 && d.in != in) continue;
if (d.out != -1 && d.out != out) continue;
if (d.in == -1 && d.out == -1 && out <= 2) continue;
Expand Down
13 changes: 5 additions & 8 deletions libs/ardour/playlist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1426,11 +1426,9 @@ Playlist::duplicate_ranges (std::list<TimelineRange>& ranges, float times)
timepos_t min_pos = timepos_t::max (ranges.front().start().time_domain());
timepos_t max_pos = timepos_t (min_pos.time_domain());

for (std::list<TimelineRange>::const_iterator i = ranges.begin();
i != ranges.end();
++i) {
min_pos = min (min_pos, (*i).start());
max_pos = max (max_pos, (*i).end());
for (const TimelineRange& i : ranges) {
min_pos = min (min_pos, i.start());
max_pos = max (max_pos, i.end());
}

timecnt_t offset = min_pos.distance (max_pos);
Expand Down Expand Up @@ -2403,9 +2401,8 @@ Playlist::state (bool full_state) const
node->set_property (X_("pgroup-id"), _pgroup_id);

string shared_ids;
list<PBD::ID>::const_iterator it = _shared_with_ids.begin ();
for (; it != _shared_with_ids.end (); ++it) {
shared_ids += "," + (*it).to_s ();
for (const PBD::ID& it : _shared_with_ids) {
shared_ids += "," + it.to_s ();
}
if (!shared_ids.empty ()) {
shared_ids.erase (0, 1);
Expand Down
5 changes: 2 additions & 3 deletions libs/ardour/route.cc
Original file line number Diff line number Diff line change
Expand Up @@ -845,9 +845,8 @@ static void
dump_processors(const string& name, const list<std::shared_ptr<Processor> >& procs)
{
cerr << name << " {" << endl;
for (list<std::shared_ptr<Processor> >::const_iterator p = procs.begin();
p != procs.end(); ++p) {
cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
for (const std::shared_ptr<Processor> & p : procs) {
cerr << "\t" << p->name() << " ID = " << p->id() << " @ " << p << endl;
}
cerr << "}" << endl;
}
Expand Down
23 changes: 11 additions & 12 deletions libs/ardour/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4725,16 +4725,16 @@ Session::set_session_range_is_free (bool yn)
void
Session::playlist_ranges_moved (list<Temporal::RangeMove> const & ranges)
{
for (list<Temporal::RangeMove>::const_iterator i = ranges.begin(); i != ranges.end(); ++i) {
maybe_update_session_range (i->from, i->to);
for (const Temporal::RangeMove& i : ranges) {
maybe_update_session_range (i.from, i.to);
}
}

void
Session::playlist_regions_extended (list<Temporal::Range> const & ranges)
{
for (list<Temporal::Range>::const_iterator i = ranges.begin(); i != ranges.end(); ++i) {
maybe_update_session_range (i->start(), i->end());
for (const Temporal::Range& i : ranges) {
maybe_update_session_range (i.start(), i.end());
}
}

Expand Down Expand Up @@ -4769,8 +4769,8 @@ Session::destroy_sources (list<std::shared_ptr<Source> > const& srcs)
{
set<std::shared_ptr<Region> > relevant_regions;

for (list<std::shared_ptr<Source> >::const_iterator s = srcs.begin(); s != srcs.end(); ++s) {
RegionFactory::get_regions_using_source (*s, relevant_regions);
for (const std::shared_ptr<Source> & s : srcs) {
RegionFactory::get_regions_using_source (s, relevant_regions);
}

for (set<std::shared_ptr<Region> >::iterator r = relevant_regions.begin(); r != relevant_regions.end();) {
Expand All @@ -4783,17 +4783,16 @@ Session::destroy_sources (list<std::shared_ptr<Source> > const& srcs)
r = relevant_regions.erase (r);
}

for (list<std::shared_ptr<Source> >::const_iterator s = srcs.begin(); s != srcs.end(); ++s) {

for (const std::shared_ptr<Source> & s : srcs) {
{
Glib::Threads::Mutex::Lock ls (source_lock);
/* remove from the main source list */
sources.erase ((*s)->id());
sources.erase (s->id());
}

(*s)->mark_for_remove ();
(*s)->drop_references ();
SourceRemoved (std::weak_ptr<Source> (*s)); /* EMIT SIGNAL */
s->mark_for_remove ();
s->drop_references ();
SourceRemoved (std::weak_ptr<Source> (s)); /* EMIT SIGNAL */
}

return 0;
Expand Down
23 changes: 9 additions & 14 deletions libs/ardour/session_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1297,8 +1297,8 @@ Session::state (bool save_template, snapshot_t snapshot_type, bool for_archive,
list<XMLNode*> midi_port_nodes = _midi_ports->get_midi_port_states();
if (!midi_port_nodes.empty()) {
XMLNode* midi_port_stuff = new XMLNode ("MIDIPorts");
for (list<XMLNode*>::const_iterator n = midi_port_nodes.begin(); n != midi_port_nodes.end(); ++n) {
midi_port_stuff->add_child_nocopy (**n);
for (XMLNode* const& n : midi_port_nodes) {
midi_port_stuff->add_child_nocopy (*n);
}
node->add_child_nocopy (*midi_port_stuff);
}
Expand Down Expand Up @@ -1535,8 +1535,8 @@ Session::state (bool save_template, snapshot_t snapshot_type, bool for_archive,
_playlists->add_state (node, save_template, !only_used_assets);

child = node->add_child ("RouteGroups");
for (list<RouteGroup *>::const_iterator i = _route_groups.begin(); i != _route_groups.end(); ++i) {
child->add_child_nocopy ((*i)->get_state());
for (RouteGroup * const& i : _route_groups) {
child->add_child_nocopy (i->get_state());
}

if (_click_io) {
Expand Down Expand Up @@ -3261,19 +3261,14 @@ Session::possible_states () const
RouteGroup*
Session::new_route_group (const std::string& name)
{
RouteGroup* rg = NULL;

for (std::list<RouteGroup*>::const_iterator i = _route_groups.begin (); i != _route_groups.end (); ++i) {
if ((*i)->name () == name) {
rg = *i;
break;
for (RouteGroup* const& rg : _route_groups) {
if (rg->name () == name) {
return rg;
}
}

if (!rg) {
rg = new RouteGroup (*this, name);
add_route_group (rg);
}
RouteGroup* rg = new RouteGroup (*this, name);
add_route_group (rg);
return (rg);
}

Expand Down
6 changes: 2 additions & 4 deletions libs/ardour/transform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@ Transform::operator()(std::shared_ptr<MidiModel> model,
// Clear stack and run program
ctx.stack = std::stack<Variant>();
ctx.this_note = note;
for (std::list<Operation>::const_iterator o = _prog.ops.begin();
o != _prog.ops.end();
++o) {
(*o).eval(ctx);
for (const Operation& o : _prog.ops) {
o.eval(ctx);
}

// Result is on top of the stack
Expand Down
4 changes: 2 additions & 2 deletions libs/canvas/benchmark/render_from_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class RenderFromLog : public Benchmark

list<Rect> const & renders = canvas.renders ();

for (list<Rect>::const_iterator i = renders.begin(); i != renders.end(); ++i) {
canvas.render_to_image (*i);
for (const Rect& i : renders) {
canvas.render_to_image (i);
}
}

Expand Down
4 changes: 2 additions & 2 deletions libs/canvas/box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ Box::size_request (Distance& w, Distance& h) const
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("size request for %1\n", this));
if (homogenous) {

for (std::list<Item*>::const_iterator i = _items.begin(); i != _items.end(); ++i) {
for (Item* const& i : _items) {
Distance iw, ih;
(*i)->size_request (iw, ih);
i->size_request (iw, ih);

largest_height = std::max (largest_height, ih);
largest_width = std::max (largest_width, iw);
Expand Down
10 changes: 5 additions & 5 deletions libs/canvas/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,10 @@ Canvas::window_to_canvas (Duple const & d) const
in_window.y = 0;
}

for (list<ScrollGroup*>::const_iterator s = scrollers.begin(); s != scrollers.end(); ++s) {
for (ScrollGroup* const& s : scrollers) {

if ((*s)->covers_window (in_window)) {
sg = *s;
if (s->covers_window (in_window)) {
sg = s;

/* XXX January 22nd 2015: leaving this in place for now
* but I think it fixes a bug that really should be
Expand Down Expand Up @@ -408,8 +408,8 @@ Canvas::canvas_to_window (Duple const & d, bool rounded) const
ScrollGroup* sg = 0;
Duple wd;

for (std::list<Item*>::const_iterator i = root_children.begin(); i != root_children.end(); ++i) {
if (((sg = dynamic_cast<ScrollGroup*>(*i)) != 0) && sg->covers_canvas (d)) {
for (Item* const& i : root_children) {
if (((sg = dynamic_cast<ScrollGroup*>(i)) != 0) && sg->covers_canvas (d)) {
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions libs/gtkmm2ext/bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -790,15 +790,15 @@ Bindings::save_all_bindings_as_html (ostream& ostr)

/* first column: separate by group */
ostr << "<td>\n\n";
for (list<Bindings*>::const_iterator b = bindings.begin(); b != bindings.end(); ++b) {
(*b)->save_as_html (ostr, true);
for (Bindings* const& b : bindings) {
b->save_as_html (ostr, true);
}
ostr << "</td>\n\n";

//second column
ostr << "<td style=\"vertical-align:top\">\n\n";
for (list<Bindings*>::const_iterator b = bindings.begin(); b != bindings.end(); ++b) {
(*b)->save_as_html (ostr, false);
for (Bindings* const& b : bindings) {
b->save_as_html (ostr, false);
}
ostr << "</td>\n\n";

Expand Down
4 changes: 2 additions & 2 deletions libs/gtkmm2ext/gtk_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,12 @@ UI::dump_errors (std::ostream& ostr, size_t limit)
}

if (first) {
for (list<string>::const_iterator i = error_stack.begin(); i != error_stack.end(); ++i) {
for (const string& i : error_stack) {
if (first) {
ostr << endl << X_("Log Messages:") << endl;
first = false;
}
ostr << *i << endl;
ostr << i << endl;
if (limit > 0) {
if (--limit == 0) {
ostr << "..." << endl;
Expand Down
4 changes: 2 additions & 2 deletions libs/gtkmm2ext/gtkmm2ext/dndtreeview.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ class /*LIBGTKMM2EXT_API*/ DnDTreeView : public DnDTreeViewBase
} else {
/* some kind of target type, usually 'object_type' added by the app,
* which will be handled by a signal handler */
for (std::list<Gtk::TargetEntry>::const_iterator i = draggable.begin(); i != draggable.end (); ++i) {
if (selection_data.get_target() == (*i).get_target()) {
for (const Gtk::TargetEntry& i : draggable) {
if (selection_data.get_target() == i.get_target()) {
signal_drop (context, selection_data);
context->drag_finish (true, false, time);
break;
Expand Down
Loading

0 comments on commit 22a9b49

Please sign in to comment.