Re: [PATCH 04/34] kernelshark: Do not create a temporary container for looping over QMap

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 1/28/24 22:30, Benjamin ROBIN wrote:
On Sun, Jan 21, 2024 at 07:16:01PM +0200, Yordan Karadzhov wrote:


On 1/14/24 19:16, Benjamin ROBIN wrote:
Use const_iterator instead. Fix container-anti-pattern Clazy warning

Signed-off-by: Benjamin ROBIN <dev@xxxxxxxxxxxxx>
---
   src/KsAdvFilteringDialog.cpp | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/KsAdvFilteringDialog.cpp b/src/KsAdvFilteringDialog.cpp
index 4683c3d..247f912 100644
--- a/src/KsAdvFilteringDialog.cpp
+++ b/src/KsAdvFilteringDialog.cpp
@@ -276,8 +276,8 @@ void KsAdvFilteringDialog::_makeFilterTable()
   	headers << "Delete" << "Stream" << "Event" << " Id" << "Filter";
   	_table->init(headers, _filters.count());
-	for(auto f : _filters.keys()) {
-		QStringList thisFilter = _filters.value(f).split(":");
+	for (auto it = _filters.cbegin(), end = _filters.cend(); it != end; ++it) {

Do we need to use iterator here?
Perhaps you can do something like:

for (const auto &[key, val] : _filters) {

Unfortunately, you cannot do that, as far as I know (this not compile).
C++ range-based for loop is using iterator behind the scene. See [1].
And there is still the problem of range-loop-detach (see patch 0005).
Using const iterator is the most explicit and safe way to iterate over a
container in Qt, so why not using it?

I see your point. I am applying this patch together with all v2 patches you sent.

Are you considering sending new version of the "[31/34] Fix comparison of integers of different signs warnings"?

Thanks,
Y.


[1] https://en.cppreference.com/w/cpp/language/range-for
Thanks!
Y.

+		QStringList thisFilter = it.value().split(":");
   		i1 = new QTableWidgetItem(thisFilter[0]);
   		_table->setItem(count, 1, i1);
@@ -285,7 +285,7 @@ void KsAdvFilteringDialog::_makeFilterTable()
   		i1 = new QTableWidgetItem(thisFilter[1]);
   		_table->setItem(count, 2, i1);
-		i2 = new QTableWidgetItem(tr("%1").arg(f));
+		i2 = new QTableWidgetItem(tr("%1").arg(it.key()));
   		_table->setItem(count, 3, i2);
   		i3 = new QTableWidgetItem(thisFilter[2]);




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux