From: Uwe Hermann Date: Mon, 8 Feb 2016 20:02:37 +0000 (+0100) Subject: Use range-based for loops more often. X-Git-Tag: pulseview-0.4.0~338 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=da50281d69f15d125b56971a3009fd31cbbab58b;p=pulseview.git Use range-based for loops more often. This patch was generated using clang-tidy: clang-tidy -checks="-*,modernize-loop-convert" -fix --- diff --git a/pv/data/decode/decoder.cpp b/pv/data/decode/decoder.cpp index 03f4f0eb..374dd4d3 100644 --- a/pv/data/decode/decoder.cpp +++ b/pv/data/decode/decoder.cpp @@ -44,8 +44,8 @@ Decoder::Decoder(const srd_decoder *const dec) : Decoder::~Decoder() { - for (auto i = options_.begin(); i != options_.end(); i++) - g_variant_unref((*i).second); + for (auto & option : options_) + g_variant_unref(option.second); } const srd_decoder* Decoder::decoder() const @@ -102,8 +102,8 @@ bool Decoder::have_required_channels() const set< shared_ptr > Decoder::get_data() { set< shared_ptr > data; - for (auto i = channels_.cbegin(); i != channels_.cend(); i++) { - shared_ptr signal((*i).second); + for (const auto & channel : channels_) { + shared_ptr signal(channel.second); assert(signal); data.insert(signal->logic_data()); } @@ -116,12 +116,11 @@ srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session) const GHashTable *const opt_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_variant_unref); - for (auto i = options_.cbegin(); i != options_.cend(); i++) - { - GVariant *const value = (*i).second; + for (const auto & option : options_) { + GVariant *const value = option.second; g_variant_ref(value); g_hash_table_replace(opt_hash, (void*)g_strdup( - (*i).first.c_str()), value); + option.first.c_str()), value); } srd_decoder_inst *const decoder_inst = srd_inst_new( @@ -135,13 +134,12 @@ srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session) const GHashTable *const channels = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_variant_unref); - for (auto i = channels_.cbegin(); i != channels_.cend(); i++) - { - shared_ptr signal((*i).second); + for (const auto & channel : channels_) { + shared_ptr signal(channel.second); GVariant *const gvar = g_variant_new_int32( signal->channel()->index()); g_variant_ref_sink(gvar); - g_hash_table_insert(channels, (*i).first->id, gvar); + g_hash_table_insert(channels, channel.first->id, gvar); } srd_inst_channel_set_all(decoder_inst, channels); diff --git a/pv/data/decode/rowdata.cpp b/pv/data/decode/rowdata.cpp index 9402e707..e7d82fd7 100644 --- a/pv/data/decode/rowdata.cpp +++ b/pv/data/decode/rowdata.cpp @@ -41,10 +41,10 @@ void RowData::get_annotation_subset( vector &dest, uint64_t start_sample, uint64_t end_sample) const { - for (auto i = annotations_.cbegin(); i != annotations_.cend(); i++) - if ((*i).end_sample() > start_sample && - (*i).start_sample() <= end_sample) - dest.push_back(*i); + for (const auto & annotation : annotations_) + if (annotation.end_sample() > start_sample && + annotation.start_sample() <= end_sample) + dest.push_back(annotation); } void RowData::push_annotation(const Annotation &a) diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 59354735..b79326d8 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -272,9 +272,9 @@ uint64_t DecoderStack::max_sample_count() const { uint64_t max_sample_count = 0; - for (auto i = rows_.cbegin(); i != rows_.end(); i++) + for (const auto & row : rows_) max_sample_count = max(max_sample_count, - (*i).second.get_max_sample()); + row.second.get_max_sample()); return max_sample_count; } diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 95e0e5e9..b2ead1a6 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -199,8 +199,8 @@ void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp) const vector rows(decoder_stack_->get_visible_rows()); visible_rows_.clear(); - for (size_t i = 0; i < rows.size(); i++) { - const Row &row = rows[i]; + for (auto i : rows) { + const Row &row = i; // Cache the row title widths int row_title_width; @@ -229,7 +229,7 @@ void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp) y += row_height_; - visible_rows_.push_back(rows[i]); + visible_rows_.push_back(i); } }