From 486bcf0119d06242f624d47aef74d6d29c828f94 Mon Sep 17 00:00:00 2001 From: Soeren Apel Date: Thu, 14 Mar 2019 12:24:04 +0100 Subject: [PATCH] DecoderSelector: Rework GSList usage to remove unnecessary list copying --- pv/subwindows/decoder_selector/model.cpp | 8 ++----- pv/subwindows/decoder_selector/subwindow.cpp | 22 ++++++-------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/pv/subwindows/decoder_selector/model.cpp b/pv/subwindows/decoder_selector/model.cpp index 07faee8e..31dfd464 100644 --- a/pv/subwindows/decoder_selector/model.cpp +++ b/pv/subwindows/decoder_selector/model.cpp @@ -51,8 +51,7 @@ DecoderCollectionModel::DecoderCollectionModel(QObject* parent) : make_shared(item_data, root_); root_->appendSubItem(group_item_all); - GSList* l = g_slist_copy((GSList*)srd_decoder_list()); - for (GSList* li = l; li; li = li->next) { + for (GSList* li = (GSList*)srd_decoder_list(); li; li = li->next) { const srd_decoder *const d = (srd_decoder*)li->data; assert(d); @@ -70,8 +69,7 @@ DecoderCollectionModel::DecoderCollectionModel(QObject* parent) : group_item_all->appendSubItem(decoder_item_all); // Add decoder to all relevant groups using the tag information - GSList* t = g_slist_copy((GSList*)d->tags); - for (GSList* ti = t; ti; ti = ti->next) { + for (GSList* ti = (GSList*)d->tags; ti; ti = ti->next) { const QString tag = tr((char*)ti->data); const QVariant tag_var = QVariant(tag); @@ -101,9 +99,7 @@ DecoderCollectionModel::DecoderCollectionModel(QObject* parent) : // Add decoder to tag group group_item->appendSubItem(decoder_item); } - g_slist_free(t); } - g_slist_free(l); } QVariant DecoderCollectionModel::data(const QModelIndex& index, int role) const diff --git a/pv/subwindows/decoder_selector/subwindow.cpp b/pv/subwindows/decoder_selector/subwindow.cpp index 719d2efa..e6245ab4 100644 --- a/pv/subwindows/decoder_selector/subwindow.cpp +++ b/pv/subwindows/decoder_selector/subwindow.cpp @@ -141,15 +141,13 @@ const srd_decoder* SubWindow::get_srd_decoder_from_id(QString id) const { const srd_decoder* ret_val = nullptr; - GSList* l = g_slist_copy((GSList*)srd_decoder_list()); - for (GSList* li = l; li; li = li->next) { + for (GSList* li = (GSList*)srd_decoder_list(); li; li = li->next) { const srd_decoder* d = (srd_decoder*)li->data; assert(d); if (QString::fromUtf8(d->id) == id) ret_val = d; } - g_slist_free(l); return ret_val; } @@ -158,12 +156,8 @@ vector SubWindow::decoder_inputs(const srd_decoder* d) const { vector ret_val; - GSList* l = g_slist_copy(d->inputs); - for (GSList* li = l; li; li = li->next) { - const char* input = (const char*)li->data; - ret_val.push_back(input); - } - g_slist_free(l); + for (GSList* li = d->inputs; li; li = li->next) + ret_val.push_back((const char*)li->data); return ret_val; } @@ -172,8 +166,7 @@ vector SubWindow::decoders_providing(const char* output) con { vector ret_val; - GSList* l = g_slist_copy((GSList*)srd_decoder_list()); - for (GSList* li = l; li; li = li->next) { + for (GSList* li = (GSList*)srd_decoder_list(); li; li = li->next) { const srd_decoder* d = (srd_decoder*)li->data; assert(d); @@ -184,7 +177,6 @@ vector SubWindow::decoders_providing(const char* output) con if (strncmp((char*)(d->outputs->data), output, strlen(output)) == 0) ret_val.push_back(d); } - g_slist_free(l); return ret_val; } @@ -208,14 +200,12 @@ void SubWindow::on_item_changed(const QModelIndex& index) const QString doc = QString::fromUtf8(srd_decoder_doc_get(d)); QString tags; - GSList* l = g_slist_copy((GSList*)d->tags); - for (GSList* li = l; li; li = li->next) { - QString s = (li == l) ? + for (GSList* li = (GSList*)d->tags; li; li = li->next) { + QString s = (li == (GSList*)d->tags) ? tr((char*)li->data) : QString(tr(", %1")).arg(tr((char*)li->data)); tags.append(s); } - g_slist_free(l); info_label_header_->setText(QString("%1 (%2)
%3") .arg(longname, id, desc)); -- 2.30.2