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
// in the meta array (ie: mimetype, url), and we want
// something homogenous and easy to save.
for (map<string,string>::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);

View File

@ -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) {

View File

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

View File

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

View File

@ -61,8 +61,8 @@ void output_fields(vector<string> fields, Rcl::Doc& doc,
{
if (fields.empty()) {
map<string,string>::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<string>::const_iterator it = fields.begin();
@ -406,9 +406,8 @@ endopts:
<< doc.fbytes << "\tbytes" << "\t"
<< endl;
if (op_flags & OPT_m) {
for (map<string,string>::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) {

View File

@ -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<string,string>::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;

View File

@ -32,9 +32,8 @@ public:
{
LOGDEB1("Comparing .. \n" );
map<string,string>::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;

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
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;
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);

View File

@ -18,7 +18,7 @@
#define _RCLDOC_H_INCLUDED_
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#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<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
// of doc, not a native document attribute. Not stored directly, but

View File

@ -37,6 +37,8 @@
#include "safesysstat.h"
#include <mutex>
#include <map>
#include <unordered_map>
#include "rclutil.h"
#include "pathut.h"
@ -49,15 +51,18 @@
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();
it != s.end(); it++) {
for (const auto& ent : s) {
d->insert(
pair<string, string>(string(it->first.begin(), it->first.end()),
string(it->second.begin(), it->second.end())));
pair<string, string>(string(ent.first.begin(), ent.first.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
static bool path_hasdrive(const string& s)

View File

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