]> sigrok.org Git - pulseview.git/commitdiff
Use range-based for loops more often.
authorUwe Hermann <redacted>
Mon, 8 Feb 2016 20:02:37 +0000 (21:02 +0100)
committerUwe Hermann <redacted>
Sat, 13 Feb 2016 19:41:33 +0000 (20:41 +0100)
This patch was generated using clang-tidy:

  clang-tidy -checks="-*,modernize-loop-convert" -fix

pv/data/decode/decoder.cpp
pv/data/decode/rowdata.cpp
pv/data/decoderstack.cpp
pv/view/decodetrace.cpp

index 03f4f0ebabdfc4cae68af572163d1b5345e49a98..374dd4d360c9bf8bca84f544eaf04892395c9888 100644 (file)
@@ -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<pv::data::Logic> > Decoder::get_data()
 {
        set< shared_ptr<pv::data::Logic> > data;
-       for (auto i = channels_.cbegin(); i != channels_.cend(); i++) {
-               shared_ptr<view::LogicSignal> signal((*i).second);
+       for (const auto & channel : channels_) {
+               shared_ptr<view::LogicSignal> 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<view::LogicSignal> signal((*i).second);
+       for (const auto & channel : channels_) {
+               shared_ptr<view::LogicSignal> 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);
index 9402e707503e63772c9c18a39d5ea98415ed433e..e7d82fd72c5a77713980f1f7e6c69b714a4c59cb 100644 (file)
@@ -41,10 +41,10 @@ void RowData::get_annotation_subset(
        vector<pv::data::decode::Annotation> &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)
index 59354735d1e328ee6cdd8d23a717ec7763f6fce6..b79326d83363ed70efa20580a62bdf4068dcddbe 100644 (file)
@@ -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;
 }
index 95e0e5e9ef0f2d4ddfd0692da1ab478846351190..b2ead1a66848600e1ae11425fe874d708b73f39a 100644 (file)
@@ -199,8 +199,8 @@ void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
        const vector<Row> 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);
                }
        }