make doc.meta an unordered_map

This commit is contained in:
Jean-Francois Dockes 2019-04-20 15:04:19 +02:00
parent 44cd3fd633
commit 54f0eda990
12 changed files with 44 additions and 45 deletions

View File

@ -157,9 +157,8 @@ public:
// way. We need it because not all interesting doc fields are // way. We need it because not all interesting doc fields are
// in the meta array (ie: mimetype, url), and we want // in the meta array (ie: mimetype, url), and we want
// something homogenous and easy to save. // something homogenous and easy to save.
for (map<string,string>::const_iterator it = doc.meta.begin(); for (const auto& entry : doc.meta) {
it != doc.meta.end(); it++) { m_fields.set(entry.first, entry.second, cstr_null);
m_fields.set((*it).first, (*it).second, cstr_null);
} }
m_fields.set(cstr_url, doc.url, cstr_null); m_fields.set(cstr_url, doc.url, cstr_null);
m_fields.set(cstr_bgc_mimetype, doc.mimetype, cstr_null); m_fields.set(cstr_bgc_mimetype, doc.mimetype, cstr_null);

View File

@ -1571,7 +1571,8 @@ Db_init(recoll_DbObject *self, PyObject *args, PyObject *kwargs)
return -1; return -1;
// If the user creates several dbs, changing the confdir, we call // If the user creates several dbs, changing the confdir, we call
// recollinit repeatedly, which *should* be ok... // recollinit repeatedly, which *should* be ok, except that it
// resets the log file.
string reason; string reason;
delete rclconfig; delete rclconfig;
if (confdir) { if (confdir) {

View File

@ -954,11 +954,10 @@ void PreviewTextEdit::displayFields()
txt += "|" + QString::fromUtf8(m_ipath.c_str()); txt += "|" + QString::fromUtf8(m_ipath.c_str());
txt += "</b><br><br>"; txt += "</b><br><br>";
txt += "<dl>\n"; txt += "<dl>\n";
for (map<string,string>::const_iterator it = m_fdoc.meta.begin(); for (const auto& entry: m_fdoc.meta) {
it != m_fdoc.meta.end(); it++) { if (!entry.second.empty())
if (!it->second.empty()) txt += "<dt>" + QString::fromUtf8(entry.first.c_str()) + "</dt> "
txt += "<dt>" + QString::fromUtf8(it->first.c_str()) + "</dt> " + "<dd>" + QString::fromUtf8(escapeHtml(entry.second).c_str())
+ "<dd>" + QString::fromUtf8(escapeHtml(it->second).c_str())
+ "</dd>\n"; + "</dd>\n";
} }
txt += "</dl></body></html>"; txt += "</dl></body></html>";

View File

@ -416,9 +416,8 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term)
subs["U"] = url_encode(url); subs["U"] = url_encode(url);
subs["u"] = url; subs["u"] = url;
// Let %(xx) access all metadata. // Let %(xx) access all metadata.
for (map<string,string>::const_iterator it = doc.meta.begin(); for (const auto& ent :doc.meta) {
it != doc.meta.end(); it++) { subs[ent.first] = ent.second;
subs[it->first] = it->second;
} }
execViewer(subs, enterHistory, execpath, lcmd, cmd, doc, execwflags); execViewer(subs, enterHistory, execpath, lcmd, cmd, doc, execwflags);
} }

View File

@ -162,7 +162,7 @@ void ResTableDetailArea::createPopupMenu(const QPoint& pos)
// little processing // little processing
static string gengetter(const string& fld, const Rcl::Doc& doc) static string gengetter(const string& fld, const Rcl::Doc& doc)
{ {
map<string, string>::const_iterator it = doc.meta.find(fld); const auto it = doc.meta.find(fld);
if (it == doc.meta.end()) { if (it == doc.meta.end()) {
return string(); 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) static string sizegetter(const string& fld, const Rcl::Doc& doc)
{ {
map<string, string>::const_iterator it = doc.meta.find(fld); const auto it = doc.meta.find(fld);
if (it == doc.meta.end()) { if (it == doc.meta.end()) {
return string(); return string();
} }

View File

@ -61,8 +61,8 @@ void output_fields(vector<string> fields, Rcl::Doc& doc,
{ {
if (fields.empty()) { if (fields.empty()) {
map<string,string>::const_iterator it; map<string,string>::const_iterator it;
for (it = doc.meta.begin();it != doc.meta.end(); it++) { for (const auto& entry : doc.meta) {
fields.push_back(it->first); fields.push_back(entry.first);
} }
} }
for (vector<string>::const_iterator it = fields.begin(); for (vector<string>::const_iterator it = fields.begin();
@ -406,9 +406,8 @@ endopts:
<< doc.fbytes << "\tbytes" << "\t" << doc.fbytes << "\tbytes" << "\t"
<< endl; << endl;
if (op_flags & OPT_m) { if (op_flags & OPT_m) {
for (map<string,string>::const_iterator it = doc.meta.begin(); for (const auto ent : doc.meta) {
it != doc.meta.end(); it++) { cout << ent.first << " = " << ent.second << endl;
cout << it->first << " = " << it->second << endl;
} }
} }
if (op_flags & OPT_A) { if (op_flags & OPT_A) {

View File

@ -313,10 +313,9 @@ void ResListPager::displayDoc(RclConfig *config, int i, Rcl::Doc& doc,
subs["x"] = xdocidbuf; subs["x"] = xdocidbuf;
// Let %(xx) access all metadata. HTML-neuter everything: // Let %(xx) access all metadata. HTML-neuter everything:
for (map<string,string>::iterator it = doc.meta.begin(); for (const auto& entry : doc.meta) {
it != doc.meta.end(); it++) { if (!entry.first.empty())
if (!it->first.empty()) subs[entry.first] = maybeEscapeHtml(entry.second);
subs[it->first] = maybeEscapeHtml(it->second);
} }
string formatted; string formatted;

View File

@ -32,9 +32,8 @@ public:
{ {
LOGDEB1("Comparing .. \n" ); LOGDEB1("Comparing .. \n" );
map<string,string>::const_iterator xit, yit; const auto xit = x->meta.find(ss.field);
xit = x->meta.find(ss.field); const auto yit = y->meta.find(ss.field);
yit = y->meta.find(ss.field);
if (xit == x->meta.end() || yit == y->meta.end()) if (xit == x->meta.end() || yit == y->meta.end())
return 0; return 0;
return ss.desc ? yit->second < xit->second : xit->second < yit->second; return ss.desc ? yit->second < xit->second : xit->second < yit->second;

View File

@ -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 // Clear the term lists for the incoming fields and index the new values
map<string, string>::iterator meta_it; map<string, string>::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; 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 [" << LOGDEB0("Db::xattrOnly: no prefix for field [" <<
meta_it->first << "], skipped\n"); ent.first << "], skipped\n");
continue; continue;
} }
// Clear the previous terms for the field // Clear the previous terms for the field
clearField(xdoc, ftp->pfx, ftp->wdfinc); 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 << ": [" << ftp->pfx << "] inc " << ftp->wdfinc << ": [" <<
meta_it->second << "]\n"); ent.second << "]\n");
splitter->setTraits(*ftp); splitter->setTraits(*ftp);
if (!splitter->text_to_words(meta_it->second)) { if (!splitter->text_to_words(ent.second)) {
LOGDEB("Db::xattrOnly: split failed for " << meta_it->first << "\n"); LOGDEB("Db::xattrOnly: split failed for " << ent.first << "\n");
} }
} }
xdoc.add_value(VALUE_SIG, doc.sig); xdoc.add_value(VALUE_SIG, doc.sig);

View File

@ -18,7 +18,7 @@
#define _RCLDOC_H_INCLUDED_ #define _RCLDOC_H_INCLUDED_
#include <string> #include <string>
#include <map> #include <unordered_map>
#include <vector> #include <vector>
#include "smallut.h" #include "smallut.h"
@ -79,7 +79,7 @@ public:
// Only some predefined fields are stored in the data record: // Only some predefined fields are stored in the data record:
// "title", "keywords", "abstract", "author", but if a field name is // "title", "keywords", "abstract", "author", but if a field name is
// in the "stored" configuration list, it will be stored too. // in the "stored" configuration list, it will be stored too.
std::map<std::string, std::string> meta; std::unordered_map<std::string, std::string> meta;
// Attribute for the "abstract" entry. true if it is just the top // Attribute for the "abstract" entry. true if it is just the top
// of doc, not a native document attribute. Not stored directly, but // of doc, not a native document attribute. Not stored directly, but

View File

@ -37,6 +37,8 @@
#include "safesysstat.h" #include "safesysstat.h"
#include <mutex> #include <mutex>
#include <map>
#include <unordered_map>
#include "rclutil.h" #include "rclutil.h"
#include "pathut.h" #include "pathut.h"
@ -49,15 +51,18 @@
using namespace std; using namespace std;
void map_ss_cp_noshr(const map<string, string> s, map<string, string> *d) template <class T> void map_ss_cp_noshr(T s, T *d)
{ {
for (map<string, string>::const_iterator it = s.begin(); for (const auto& ent : s) {
it != s.end(); it++) {
d->insert( d->insert(
pair<string, string>(string(it->first.begin(), it->first.end()), pair<string, string>(string(ent.first.begin(), ent.first.end()),
string(it->second.begin(), it->second.end()))); string(ent.second.begin(), ent.second.end())));
} }
} }
template void map_ss_cp_noshr<map<string, string> >(
map<string, string> s, map<string, string>*d);
template void map_ss_cp_noshr<unordered_map<string, string> >(
unordered_map<string,string> s, unordered_map<string,string>*d);
#ifdef _WIN32 #ifdef _WIN32
static bool path_hasdrive(const string& s) static bool path_hasdrive(const string& s)

View File

@ -94,10 +94,9 @@ private:
extern bool thumbPathForUrl(const std::string& url, int size, extern bool thumbPathForUrl(const std::string& url, int size,
std::string& path); std::string& path);
// Duplicate map<string,string> while ensuring no shared string data (to pass // Duplicate (unordered)map<string,string> while ensuring no shared
// to other thread): // string data (to pass to other thread):
void map_ss_cp_noshr(const std::map<std::string, std::string> s, template <class T> void map_ss_cp_noshr(T s, T *d);
std::map<std::string, std::string> *d);
#endif /* _RCLUTIL_H_INCLUDED_ */ #endif /* _RCLUTIL_H_INCLUDED_ */