[utilities/krusader] app/Dialogs: PopularUrls: Deduplicate code. Simplify logic

Toni Asensi Esteve <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 89ef4eefa7705c2a252465ee371ee8d4270ce2ec by Toni Asensi Esteve.
Committed on 16/08/2026 at 22:14.
Pushed by asensi into branch 'master'.

PopularUrls: Deduplicate code. Simplify logic

Revision: https://invent.kde.org/utilities/krusader/-/merge_requests/193

M  +8    -12   app/Dialogs/popularurls.cpp

https://invent.kde.org/utilities/krusader/-/commit/89ef4eefa7705c2a252465ee371ee8d4270ce2ec

diff --git a/app/Dialogs/popularurls.cpp b/app/Dialogs/popularurls.cpp
index 60e794456..82e01fc3c 100644
--- a/app/Dialogs/popularurls.cpp
+++ b/app/Dialogs/popularurls.cpp
@@ -132,23 +132,19 @@ void PopularUrls::addUrl(const QUrl &url)
     UrlNodeP pnode;
 
     decreaseRanks();
-    if (!head) { // if the list is empty ... (assumes dict to be empty as well)
+    if (!head // if the list is empty (it assumes that the dict is empty as well)
+        ||
+        ranks.find(tmpurl.url()) == ranks.end() // is the added url new? if so, append it
+        )
+    {
         pnode = new UrlNode;
         pnode->rank = STARTING_RANK;
         pnode->url = tmpurl;
         appendNode(pnode);
-        ranks.insert(tmpurl.url(), head);
+        ranks.insert(tmpurl.url(), pnode);
     } else {
-        if (ranks.find(tmpurl.url()) == ranks.end()) { // is the added url new? if so, append it
-            pnode = new UrlNode;
-            pnode->rank = STARTING_RANK;
-            pnode->url = tmpurl;
-            appendNode(pnode);
-            ranks.insert(tmpurl.url(), pnode);
-        } else {
-            pnode = ranks[tmpurl.url()];
-            pnode->rank += INCREASE;
-        }
+        pnode = ranks[tmpurl.url()];
+        pnode->rank += INCREASE;
     }
 
     // do we need to change location for this one?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.