From 708a57de1e2aab03a61a7f2ec8b0009949cffc79 Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Tue, 23 Aug 2022 04:25:36 -0400 Subject: [PATCH 1/8] add missing & for u8s2qs --- src/qtgui/recoll.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qtgui/recoll.h b/src/qtgui/recoll.h index 6214e9fa..6d2d191e 100644 --- a/src/qtgui/recoll.h +++ b/src/qtgui/recoll.h @@ -54,7 +54,7 @@ inline std::string qs2u8s(const QString& qs) { return std::string((const char *)qs.toUtf8()); } -inline QString u8s2qs(const std::string us) +inline QString u8s2qs(const std::string& us) { return QString::fromUtf8(us.c_str()); } From bed57aeaf6ecc448962fedfc9a84a3dbabca2cce Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Tue, 23 Aug 2022 04:32:43 -0400 Subject: [PATCH 2/8] simplify two true-false --- src/qtgui/restable.cpp | 2 +- src/qtgui/spell_w.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qtgui/restable.cpp b/src/qtgui/restable.cpp index 0ea206f5..597eb877 100644 --- a/src/qtgui/restable.cpp +++ b/src/qtgui/restable.cpp @@ -488,7 +488,7 @@ void RecollModel::sort(int column, Qt::SortOrder order) if (!stringlowercmp("date", spec.field) || !stringlowercmp("datetime", spec.field)) spec.field = "mtime"; - spec.desc = order == Qt::AscendingOrder ? false : true; + spec.desc = (order != Qt::AscendingOrder); } emit sortDataChanged(spec); } diff --git a/src/qtgui/spell_w.cpp b/src/qtgui/spell_w.cpp index 63ea7b57..63ff1a98 100644 --- a/src/qtgui/spell_w.cpp +++ b/src/qtgui/spell_w.cpp @@ -218,8 +218,8 @@ void SpellW::doExpand() resTW->setItem(0, 0, new QTableWidgetItem(tr("No expansion found"))); } else { int row = 0; - - if (maxexpand > 0 && int(res.entries.size()) >= maxexpand) { + // maxexpand is static const, thus guaranteed to be >0 + if (int(res.entries.size()) >= maxexpand) { resTW->setRowCount(row + 1); resTW->setSpan(row, 0, 1, 2); resTW->setItem(row++, 0, From 565a1115f7475c1283a1b88daba6201a2c1559c2 Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Tue, 23 Aug 2022 04:57:21 -0400 Subject: [PATCH 3/8] fix: a naming reuse At ~200 lines below, `it` get reused and shadowed in a for loop `QStringList::iterator it`. Eliminate it completely. If we use C++20, we can just std::set::contains() --- src/qtgui/preview_w.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qtgui/preview_w.cpp b/src/qtgui/preview_w.cpp index 43d1e080..1d0d00c9 100644 --- a/src/qtgui/preview_w.cpp +++ b/src/qtgui/preview_w.cpp @@ -782,8 +782,9 @@ bool Preview::loadDocInCurrentTab(const Rcl::Doc &idoc, int docnum) connect(<hr, SIGNAL(finished()), &loop, SLOT(quit())); bool canGetRawText = rcldb && rcldb->storesDocText(); - auto it = prefs.preferStoredTextMimes.find(idoc.mimetype); - bool preferStoredText = (it != prefs.preferStoredTextMimes.end()); + bool preferStoredText = std::find(prefs.preferStoredTextMimes.begin(), + prefs.preferStoredTextMimes.end(), + idoc.mimetype) != prefs.preferStoredTextMimes.end(); bool loadok{false}; if (!preferStoredText || !canGetRawText) { From d00ea4e4208ea25e7462063eb727750f5bbdc78c Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Tue, 23 Aug 2022 05:06:39 -0400 Subject: [PATCH 4/8] fix: asString already declared at func beginning --- src/qtgui/ssearch_w.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/qtgui/ssearch_w.cpp b/src/qtgui/ssearch_w.cpp index 504f5d18..479136b0 100644 --- a/src/qtgui/ssearch_w.cpp +++ b/src/qtgui/ssearch_w.cpp @@ -610,7 +610,6 @@ bool SSearch::fromXML(const SSearchDef& fxml) if (!checkExtIndexes(fxml.extindexes)) { - std::string asString; stringsToString(fxml.extindexes, asString); QMessageBox::warning( 0, "Recoll", From 32b74f2ac2e3b845eeff0e409990eaf0bfba4d61 Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Tue, 23 Aug 2022 05:24:33 -0400 Subject: [PATCH 5/8] fix: use std::make_shared in simple cases to reduce allocation --- src/qtgui/main.cpp | 3 ++- src/qtgui/rclm_view.cpp | 3 ++- src/qtgui/xmltosd.cpp | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index 89bd9e0c..6d7b00d6 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include "rcldb.h" #include "rclconfig.h" @@ -100,7 +101,7 @@ bool maybeOpenDb(string &reason, bool force, bool *maindberror) LOGDEB1("maybeOpenDb: force " << force << "\n"); if (force || nullptr == rcldb) { - rcldb = std::shared_ptr(new Rcl::Db(theconfig)); + rcldb = std::make_shared(theconfig); } rcldb->rmQueryDb(""); auto edbs = &prefs.activeExtraDbs; diff --git a/src/qtgui/rclm_view.cpp b/src/qtgui/rclm_view.cpp index 41d5e194..bad6eaff 100644 --- a/src/qtgui/rclm_view.cpp +++ b/src/qtgui/rclm_view.cpp @@ -22,6 +22,7 @@ #include #include +#include #include "qxtconfirmationmessage.h" @@ -75,7 +76,7 @@ void RclMain::viewUrl() Rcl::Query *query = new Rcl::Query(rcldb.get()); DocSequenceDb *src = new DocSequenceDb( rcldb, std::shared_ptr(query), "", - std::shared_ptr(new Rcl::SearchData)); + std::make_shared()); m_source = std::shared_ptr(src); diff --git a/src/qtgui/xmltosd.cpp b/src/qtgui/xmltosd.cpp index 1def6e37..f3c24e46 100644 --- a/src/qtgui/xmltosd.cpp +++ b/src/qtgui/xmltosd.cpp @@ -22,6 +22,8 @@ #include "guiutils.h" #include "log.h" #include "xmltosd.h" + +#include #include "smallut.h" #include "recoll.h" #include "picoxml.h" @@ -51,7 +53,7 @@ public: } resetTemps(); // A new search descriptor. Allocate data structure - sd = std::shared_ptr(new SearchData); + sd = std::make_shared(); if (!sd) { LOGERR("SDHXMLHandler::startElement: out of memory\n"); contentsOk = false; From 758f468e3a979285705de45ce413f373701a4b2c Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Tue, 23 Aug 2022 05:39:16 -0400 Subject: [PATCH 6/8] Remove some leftover #includes related to unused Qt components --- src/qtgui/main.cpp | 2 -- src/qtgui/restable.cpp | 1 - src/qtgui/rtitool.cpp | 1 - 3 files changed, 4 deletions(-) diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index 6d7b00d6..32576b71 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -26,12 +26,10 @@ #include #include #include -#include #include #include #include #include -#include #include #include "rcldb.h" diff --git a/src/qtgui/restable.cpp b/src/qtgui/restable.cpp index 597eb877..30311113 100644 --- a/src/qtgui/restable.cpp +++ b/src/qtgui/restable.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include diff --git a/src/qtgui/rtitool.cpp b/src/qtgui/rtitool.cpp index f4f52c7c..4bc28aa4 100644 --- a/src/qtgui/rtitool.cpp +++ b/src/qtgui/rtitool.cpp @@ -24,7 +24,6 @@ #include -#include #include #include "recoll.h" From 5608a8f79cb8a0ea0e044f20f75ab51fdf850046 Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Tue, 23 Aug 2022 05:51:08 -0400 Subject: [PATCH 7/8] && is already short-circuit evaluation abusing ? : seems unnecessary if m_stops empty -> just return false then try find -> judge if the term can be found (result of find is not the end of m_stops) --- src/rcldb/stoplist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rcldb/stoplist.cpp b/src/rcldb/stoplist.cpp index e603441b..6f0b46fc 100644 --- a/src/rcldb/stoplist.cpp +++ b/src/rcldb/stoplist.cpp @@ -50,7 +50,7 @@ bool StopList::setFile(const string &filename) // faster than find() in this case. bool StopList::isStop(const string &term) const { - return m_stops.empty() ? false : m_stops.find(term) != m_stops.end(); + return !m_stops.empty() && m_stops.find(term) != m_stops.end(); } } From 3e3711da51b63da29efcd22038d7b76fccdebea7 Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Tue, 23 Aug 2022 05:56:14 -0400 Subject: [PATCH 8/8] remove redundant .c_str() u8s2qs(takes std::string) dbd is same type of tl which is vector --- src/qtgui/guiutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qtgui/guiutils.cpp b/src/qtgui/guiutils.cpp index a501ae35..659ccf35 100644 --- a/src/qtgui/guiutils.cpp +++ b/src/qtgui/guiutils.cpp @@ -416,7 +416,7 @@ void rwSettings(bool writing) } else { vector tl = g_dynconf->getStringEntries(asbdSk); for (const auto& dbd: tl) { - prefs.asearchSubdirHist.push_back(u8s2qs(dbd.c_str())); + prefs.asearchSubdirHist.push_back(u8s2qs(dbd)); } } if (!writing) {