diff --git a/src/index/webqueue.cpp b/src/index/webqueue.cpp index d8c20527..e22097fd 100644 --- a/src/index/webqueue.cpp +++ b/src/index/webqueue.cpp @@ -157,9 +157,8 @@ public: // way. We need it because not all interesting doc fields are // in the meta array (ie: mimetype, url), and we want // something homogenous and easy to save. - for (map::const_iterator it = doc.meta.begin(); - it != doc.meta.end(); it++) { - m_fields.set((*it).first, (*it).second, cstr_null); + for (const auto& entry : doc.meta) { + m_fields.set(entry.first, entry.second, cstr_null); } m_fields.set(cstr_url, doc.url, cstr_null); m_fields.set(cstr_bgc_mimetype, doc.mimetype, cstr_null); diff --git a/src/python/recoll/pyrecoll.cpp b/src/python/recoll/pyrecoll.cpp index a48761f4..e5bbcd48 100644 --- a/src/python/recoll/pyrecoll.cpp +++ b/src/python/recoll/pyrecoll.cpp @@ -1570,8 +1570,9 @@ Db_init(recoll_DbObject *self, PyObject *args, PyObject *kwargs) &confdir, &extradbs, &writable)) return -1; - // If the user creates several dbs, changing the confdir, we call - // recollinit repeatedly, which *should* be ok... + // If the user creates several dbs, changing the confdir, we call + // recollinit repeatedly, which *should* be ok, except that it + // resets the log file. string reason; delete rclconfig; if (confdir) { diff --git a/src/qtgui/preview_w.cpp b/src/qtgui/preview_w.cpp index cebc2d41..523bcadb 100644 --- a/src/qtgui/preview_w.cpp +++ b/src/qtgui/preview_w.cpp @@ -954,11 +954,10 @@ void PreviewTextEdit::displayFields() txt += "|" + QString::fromUtf8(m_ipath.c_str()); txt += "

"; txt += "
\n"; - for (map::const_iterator it = m_fdoc.meta.begin(); - it != m_fdoc.meta.end(); it++) { - if (!it->second.empty()) - txt += "
" + QString::fromUtf8(it->first.c_str()) + "
" - + "
" + QString::fromUtf8(escapeHtml(it->second).c_str()) + for (const auto& entry: m_fdoc.meta) { + if (!entry.second.empty()) + txt += "
" + QString::fromUtf8(entry.first.c_str()) + "
" + + "
" + QString::fromUtf8(escapeHtml(entry.second).c_str()) + "
\n"; } txt += "
"; diff --git a/src/qtgui/rclm_view.cpp b/src/qtgui/rclm_view.cpp index 204b44b4..e7b38c8e 100644 --- a/src/qtgui/rclm_view.cpp +++ b/src/qtgui/rclm_view.cpp @@ -416,9 +416,8 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term) subs["U"] = url_encode(url); subs["u"] = url; // Let %(xx) access all metadata. - for (map::const_iterator it = doc.meta.begin(); - it != doc.meta.end(); it++) { - subs[it->first] = it->second; + for (const auto& ent :doc.meta) { + subs[ent.first] = ent.second; } execViewer(subs, enterHistory, execpath, lcmd, cmd, doc, execwflags); } diff --git a/src/qtgui/restable.cpp b/src/qtgui/restable.cpp index e5a92cba..49a95f0a 100644 --- a/src/qtgui/restable.cpp +++ b/src/qtgui/restable.cpp @@ -162,7 +162,7 @@ void ResTableDetailArea::createPopupMenu(const QPoint& pos) // little processing static string gengetter(const string& fld, const Rcl::Doc& doc) { - map::const_iterator it = doc.meta.find(fld); + const auto it = doc.meta.find(fld); if (it == doc.meta.end()) { return string(); } @@ -171,7 +171,7 @@ static string gengetter(const string& fld, const Rcl::Doc& doc) static string sizegetter(const string& fld, const Rcl::Doc& doc) { - map::const_iterator it = doc.meta.find(fld); + const auto it = doc.meta.find(fld); if (it == doc.meta.end()) { return string(); } diff --git a/src/query/recollq.cpp b/src/query/recollq.cpp index f38e814a..e2483f07 100644 --- a/src/query/recollq.cpp +++ b/src/query/recollq.cpp @@ -61,8 +61,8 @@ void output_fields(vector fields, Rcl::Doc& doc, { if (fields.empty()) { map::const_iterator it; - for (it = doc.meta.begin();it != doc.meta.end(); it++) { - fields.push_back(it->first); + for (const auto& entry : doc.meta) { + fields.push_back(entry.first); } } for (vector::const_iterator it = fields.begin(); @@ -406,9 +406,8 @@ endopts: << doc.fbytes << "\tbytes" << "\t" << endl; if (op_flags & OPT_m) { - for (map::const_iterator it = doc.meta.begin(); - it != doc.meta.end(); it++) { - cout << it->first << " = " << it->second << endl; + for (const auto ent : doc.meta) { + cout << ent.first << " = " << ent.second << endl; } } if (op_flags & OPT_A) { diff --git a/src/query/reslistpager.cpp b/src/query/reslistpager.cpp index 34f8512b..95208444 100644 --- a/src/query/reslistpager.cpp +++ b/src/query/reslistpager.cpp @@ -313,10 +313,9 @@ void ResListPager::displayDoc(RclConfig *config, int i, Rcl::Doc& doc, subs["x"] = xdocidbuf; // Let %(xx) access all metadata. HTML-neuter everything: - for (map::iterator it = doc.meta.begin(); - it != doc.meta.end(); it++) { - if (!it->first.empty()) - subs[it->first] = maybeEscapeHtml(it->second); + for (const auto& entry : doc.meta) { + if (!entry.first.empty()) + subs[entry.first] = maybeEscapeHtml(entry.second); } string formatted; diff --git a/src/query/sortseq.cpp b/src/query/sortseq.cpp index e7822c36..1bbc1a2e 100644 --- a/src/query/sortseq.cpp +++ b/src/query/sortseq.cpp @@ -32,9 +32,8 @@ public: { LOGDEB1("Comparing .. \n" ); - map::const_iterator xit, yit; - xit = x->meta.find(ss.field); - yit = y->meta.find(ss.field); + const auto xit = x->meta.find(ss.field); + const auto yit = y->meta.find(ss.field); if (xit == x->meta.end() || yit == y->meta.end()) return 0; return ss.desc ? yit->second < xit->second : xit->second < yit->second; diff --git a/src/rcldb/rcldb.cpp b/src/rcldb/rcldb.cpp index bf9da701..96642c15 100644 --- a/src/rcldb/rcldb.cpp +++ b/src/rcldb/rcldb.cpp @@ -1885,21 +1885,21 @@ bool Db::Native::docToXdocXattrOnly(TextSplitDb *splitter, const string &udi, // Clear the term lists for the incoming fields and index the new values map::iterator meta_it; - for (meta_it = doc.meta.begin(); meta_it != doc.meta.end(); meta_it++) { + for (const auto& ent : doc.meta) { const FieldTraits *ftp; - if (!m_rcldb->fieldToTraits(meta_it->first, &ftp) || ftp->pfx.empty()) { + if (!m_rcldb->fieldToTraits(ent.first, &ftp) || ftp->pfx.empty()) { LOGDEB0("Db::xattrOnly: no prefix for field [" << - meta_it->first << "], skipped\n"); + ent.first << "], skipped\n"); continue; } // Clear the previous terms for the field clearField(xdoc, ftp->pfx, ftp->wdfinc); - LOGDEB0("Db::xattrOnly: field [" << meta_it->first << "] pfx [" << + LOGDEB0("Db::xattrOnly: field [" << ent.first << "] pfx [" << ftp->pfx << "] inc " << ftp->wdfinc << ": [" << - meta_it->second << "]\n"); + ent.second << "]\n"); splitter->setTraits(*ftp); - if (!splitter->text_to_words(meta_it->second)) { - LOGDEB("Db::xattrOnly: split failed for " << meta_it->first << "\n"); + if (!splitter->text_to_words(ent.second)) { + LOGDEB("Db::xattrOnly: split failed for " << ent.first << "\n"); } } xdoc.add_value(VALUE_SIG, doc.sig); diff --git a/src/rcldb/rcldoc.h b/src/rcldb/rcldoc.h index a36e174c..4f7325f0 100644 --- a/src/rcldb/rcldoc.h +++ b/src/rcldb/rcldoc.h @@ -18,7 +18,7 @@ #define _RCLDOC_H_INCLUDED_ #include -#include +#include #include #include "smallut.h" @@ -79,7 +79,7 @@ public: // Only some predefined fields are stored in the data record: // "title", "keywords", "abstract", "author", but if a field name is // in the "stored" configuration list, it will be stored too. - std::map meta; + std::unordered_map meta; // Attribute for the "abstract" entry. true if it is just the top // of doc, not a native document attribute. Not stored directly, but diff --git a/src/utils/rclutil.cpp b/src/utils/rclutil.cpp index 653cdae2..08fa522e 100644 --- a/src/utils/rclutil.cpp +++ b/src/utils/rclutil.cpp @@ -37,6 +37,8 @@ #include "safesysstat.h" #include +#include +#include #include "rclutil.h" #include "pathut.h" @@ -49,15 +51,18 @@ using namespace std; -void map_ss_cp_noshr(const map s, map *d) +template void map_ss_cp_noshr(T s, T *d) { - for (map::const_iterator it = s.begin(); - it != s.end(); it++) { + for (const auto& ent : s) { d->insert( - pair(string(it->first.begin(), it->first.end()), - string(it->second.begin(), it->second.end()))); + pair(string(ent.first.begin(), ent.first.end()), + string(ent.second.begin(), ent.second.end()))); } } +template void map_ss_cp_noshr >( + map s, map*d); +template void map_ss_cp_noshr >( + unordered_map s, unordered_map*d); #ifdef _WIN32 static bool path_hasdrive(const string& s) diff --git a/src/utils/rclutil.h b/src/utils/rclutil.h index f4cb93b5..e5c9e5fc 100644 --- a/src/utils/rclutil.h +++ b/src/utils/rclutil.h @@ -94,10 +94,9 @@ private: extern bool thumbPathForUrl(const std::string& url, int size, std::string& path); -// Duplicate map while ensuring no shared string data (to pass -// to other thread): -void map_ss_cp_noshr(const std::map s, - std::map *d); +// Duplicate (unordered)map while ensuring no shared +// string data (to pass to other thread): +template void map_ss_cp_noshr(T s, T *d); #endif /* _RCLUTIL_H_INCLUDED_ */