Created
May 16, 2019 00:24
-
-
Save Kronuz/9fbf2cc8020cdcd6d8bc3957a19c2ed8 to your computer and use it in GitHub Desktop.
Xapian core Document::Internal allocator for maps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/xapian/backends/documentinternal.cc b/src/xapian/backends/documentinternal.cc | |
index ae6b9bb6c..7c87292fc 100644 | |
--- a/src/xapian/backends/documentinternal.cc | |
+++ b/src/xapian/backends/documentinternal.cc | |
@@ -41,7 +41,7 @@ Document::Internal::ensure_terms_fetched() const | |
if (terms) | |
return; | |
- terms.reset(new map<string, TermInfo>()); | |
+ terms.reset(new terms_type()); | |
termlist_size = 0; | |
if (!database.get()) | |
return; | |
@@ -66,7 +66,7 @@ Document::Internal::ensure_values_fetched() const | |
if (values) | |
return; | |
- values.reset(new map<Xapian::valueno, string>()); | |
+ values.reset(new values_type()); | |
if (database.get()) { | |
fetch_all_values(*values); | |
} | |
@@ -79,8 +79,7 @@ Document::Internal::fetch_data() const | |
} | |
void | |
-Document::Internal::fetch_all_values(map<Xapian::valueno, | |
- string>& values_) const | |
+Document::Internal::fetch_all_values(values_type& values_) const | |
{ | |
values_.clear(); | |
} | |
@@ -119,7 +118,7 @@ Xapian::ValueIterator | |
Document::Internal::values_begin() const | |
{ | |
if (!values && database.get()) { | |
- values.reset(new map<Xapian::valueno, string>()); | |
+ values.reset(new values_type()); | |
fetch_all_values(*values); | |
} | |
diff --git a/src/xapian/backends/documentinternal.h b/src/xapian/backends/documentinternal.h | |
index 132fe45af..a1aaab178 100644 | |
--- a/src/xapian/backends/documentinternal.h | |
+++ b/src/xapian/backends/documentinternal.h | |
@@ -21,6 +21,8 @@ | |
#ifndef XAPIAN_INCLUDED_DOCUMENTINTERNAL_H | |
#define XAPIAN_INCLUDED_DOCUMENTINTERNAL_H | |
+#include "allocators.h" | |
+ | |
#include "xapian/document.h" | |
#include "xapian/intrusive_ptr.h" | |
#include "xapian/types.h" | |
@@ -71,7 +73,8 @@ class Document::Internal : public Xapian::Internal::intrusive_base { | |
* invalidates existing iterators upon insert() if rehashing occurs, | |
* whereas existing iterators remain valid for std::map<>. | |
*/ | |
- mutable std::unique_ptr<std::map<std::string, TermInfo>> terms; | |
+ using terms_type = std::map<std::string, TermInfo, std::less<std::string>, allocators::memory_pool_allocator<std::pair<const std::string, TermInfo>>>; | |
+ mutable std::unique_ptr<terms_type> terms; | |
/** The number of distinct terms in @a terms. | |
* | |
@@ -116,7 +119,8 @@ class Document::Internal : public Xapian::Internal::intrusive_base { | |
* invalidates existing iterators upon insert() if rehashing occurs, | |
* whereas existing iterators remain valid for std::map<>. | |
*/ | |
- mutable std::unique_ptr<std::map<Xapian::valueno, std::string>> values; | |
+ using values_type = std::map<Xapian::valueno, std::string, std::less<Xapian::valueno>, allocators::memory_pool_allocator<std::pair<const Xapian::valueno, std::string>>>; | |
+ mutable std::unique_ptr<values_type> values; | |
/** Database this document came from. | |
* | |
@@ -142,9 +146,9 @@ class Document::Internal : public Xapian::Internal::intrusive_base { | |
Internal(const Xapian::Database::Internal* database_, | |
Xapian::docid did_, | |
const std::string& data_, | |
- std::map<Xapian::valueno, std::string>&& values_) | |
+ values_type&& values_) | |
: data(new std::string(data_)), | |
- values(new std::map<Xapian::valueno, std::string>(std::move(values_))), | |
+ values(new values_type(std::move(values_))), | |
database(database_), | |
did(did_) {} | |
@@ -160,8 +164,7 @@ class Document::Internal : public Xapian::Internal::intrusive_base { | |
* The default implementation (used when there's no associated database) | |
* clears @a values_. | |
*/ | |
- virtual void fetch_all_values(std::map<Xapian::valueno, | |
- std::string>& values_) const; | |
+ virtual void fetch_all_values(values_type& values_) const; | |
/** Fetch a single value from the database. | |
* | |
@@ -251,7 +254,7 @@ class Document::Internal : public Xapian::Internal::intrusive_base { | |
auto i = terms->find(term); | |
if (i == terms->end()) { | |
++termlist_size; | |
- terms->emplace(make_pair(term, TermInfo(wdf_inc))); | |
+ terms->emplace(term, TermInfo(wdf_inc)); | |
} else { | |
if (i->second.increase_wdf(wdf_inc)) | |
++termlist_size; | |
@@ -351,7 +354,7 @@ class Document::Internal : public Xapian::Internal::intrusive_base { | |
void clear_terms() { | |
if (!terms) { | |
if (database.get()) { | |
- terms.reset(new map<string, TermInfo>()); | |
+ terms.reset(new terms_type()); | |
termlist_size = 0; | |
} else { | |
// We didn't come from a database, so there are no unfetched | |
@@ -417,7 +420,7 @@ class Document::Internal : public Xapian::Internal::intrusive_base { | |
void clear_values() { | |
if (!values) { | |
if (database.get()) { | |
- values.reset(new map<Xapian::valueno, string>()); | |
+ values.reset(new values_type()); | |
} else { | |
// We didn't come from a database, so there are no unfetched | |
// values to clear. | |
diff --git a/src/xapian/backends/glass/glass_document.cc b/src/xapian/backends/glass/glass_document.cc | |
index c77cbad2f..772a7f043 100644 | |
--- a/src/xapian/backends/glass/glass_document.cc | |
+++ b/src/xapian/backends/glass/glass_document.cc | |
@@ -32,7 +32,7 @@ GlassDocument::fetch_value(Xapian::valueno slot) const | |
} | |
void | |
-GlassDocument::fetch_all_values(map<Xapian::valueno, string>& values_) const | |
+GlassDocument::fetch_all_values(values_type& values_) const | |
{ | |
value_manager->get_all_values(values_, did); | |
} | |
diff --git a/src/xapian/backends/glass/glass_document.h b/src/xapian/backends/glass/glass_document.h | |
index 9db293f1b..8bbf08132 100644 | |
--- a/src/xapian/backends/glass/glass_document.h | |
+++ b/src/xapian/backends/glass/glass_document.h | |
@@ -54,7 +54,7 @@ class GlassDocument : public Xapian::Document::Internal { | |
protected: | |
/** Implementation of virtual methods @{ */ | |
string fetch_value(Xapian::valueno slot) const; | |
- void fetch_all_values(map<Xapian::valueno, string> & values_) const; | |
+ void fetch_all_values(values_type& values_) const; | |
string fetch_data() const; | |
/** @} */ | |
}; | |
diff --git a/src/xapian/backends/glass/glass_values.cc b/src/xapian/backends/glass/glass_values.cc | |
index fdd993809..9778e4a3a 100644 | |
--- a/src/xapian/backends/glass/glass_values.cc | |
+++ b/src/xapian/backends/glass/glass_values.cc | |
@@ -490,7 +490,7 @@ GlassValueManager::get_value(Xapian::docid did, Xapian::valueno slot) const | |
} | |
void | |
-GlassValueManager::get_all_values(map<Xapian::valueno, string> & values, | |
+GlassValueManager::get_all_values(values_type& values, | |
Xapian::docid did) const | |
{ | |
Assert(values.empty()); | |
diff --git a/src/xapian/backends/glass/glass_values.h b/src/xapian/backends/glass/glass_values.h | |
index d450d8d9f..685164102 100644 | |
--- a/src/xapian/backends/glass/glass_values.h | |
+++ b/src/xapian/backends/glass/glass_values.h | |
@@ -22,6 +22,8 @@ | |
#ifndef XAPIAN_INCLUDED_GLASS_VALUES_H | |
#define XAPIAN_INCLUDED_GLASS_VALUES_H | |
+#include "allocators.h" | |
+ | |
#include "xapian/common/pack.h" | |
#include "xapian/backends/valuestats.h" | |
@@ -75,6 +77,8 @@ class GlassTermListTable; | |
struct ValueStats; | |
class GlassValueManager { | |
+ using values_type = std::map<Xapian::valueno, std::string, std::less<Xapian::valueno>, allocators::memory_pool_allocator<std::pair<const Xapian::valueno, std::string>>>; | |
+ | |
/** The value number for the most recently used value statistics. | |
* | |
* Set to Xapian::BAD_VALUENO if no value statistics are currently | |
@@ -131,7 +135,7 @@ class GlassValueManager { | |
std::string get_value(Xapian::docid did, Xapian::valueno slot) const; | |
- void get_all_values(std::map<Xapian::valueno, std::string> & values, | |
+ void get_all_values(values_type& values, | |
Xapian::docid did) const; | |
Xapian::doccount get_value_freq(Xapian::valueno slot) const { | |
diff --git a/src/xapian/backends/honey/honey_document.cc b/src/xapian/backends/honey/honey_document.cc | |
index 7a8e142b1..97b11f1f8 100644 | |
--- a/src/xapian/backends/honey/honey_document.cc | |
+++ b/src/xapian/backends/honey/honey_document.cc | |
@@ -32,7 +32,7 @@ HoneyDocument::fetch_value(Xapian::valueno slot) const | |
} | |
void | |
-HoneyDocument::fetch_all_values(map<Xapian::valueno, string>& values_) const | |
+HoneyDocument::fetch_all_values(values_type& values_) const | |
{ | |
value_manager->get_all_values(values_, did); | |
} | |
diff --git a/src/xapian/backends/honey/honey_document.h b/src/xapian/backends/honey/honey_document.h | |
index b5a96795d..114c11cb9 100644 | |
--- a/src/xapian/backends/honey/honey_document.h | |
+++ b/src/xapian/backends/honey/honey_document.h | |
@@ -54,7 +54,7 @@ class HoneyDocument : public Xapian::Document::Internal { | |
protected: | |
/** Implementation of virtual methods @{ */ | |
string fetch_value(Xapian::valueno slot) const; | |
- void fetch_all_values(map<Xapian::valueno, string> & values_) const; | |
+ void fetch_all_values(values_type& values_) const; | |
string fetch_data() const; | |
/** @} */ | |
}; | |
diff --git a/src/xapian/backends/honey/honey_values.cc b/src/xapian/backends/honey/honey_values.cc | |
index 53af6474f..9936ad923 100644 | |
--- a/src/xapian/backends/honey/honey_values.cc | |
+++ b/src/xapian/backends/honey/honey_values.cc | |
@@ -520,7 +520,7 @@ HoneyValueManager::get_value(Xapian::docid did, Xapian::valueno slot) const | |
} | |
void | |
-HoneyValueManager::get_all_values(map<Xapian::valueno, string> & values, | |
+HoneyValueManager::get_all_values(values_type& values, | |
Xapian::docid did) const | |
{ | |
Assert(values.empty()); | |
diff --git a/src/xapian/backends/honey/honey_values.h b/src/xapian/backends/honey/honey_values.h | |
index bb3a376b7..b2148c0bb 100644 | |
--- a/src/xapian/backends/honey/honey_values.h | |
+++ b/src/xapian/backends/honey/honey_values.h | |
@@ -22,6 +22,8 @@ | |
#ifndef XAPIAN_INCLUDED_HONEY_VALUES_H | |
#define XAPIAN_INCLUDED_HONEY_VALUES_H | |
+#include "allocators.h" | |
+ | |
#include "xapian/backends/honey/honey_cursor.h" | |
#include "xapian/backends/valuestats.h" | |
#include "xapian/common/pack.h" | |
@@ -118,6 +120,8 @@ class HoneyTermListTable; | |
struct ValueStats; | |
class HoneyValueManager { | |
+ using values_type = std::map<Xapian::valueno, std::string, std::less<Xapian::valueno>, allocators::memory_pool_allocator<std::pair<const Xapian::valueno, std::string>>>; | |
+ | |
/** The value number for the most recently used value statistics. | |
* | |
* Set to Xapian::BAD_VALUENO if no value statistics are currently | |
@@ -179,7 +183,7 @@ class HoneyValueManager { | |
std::string get_value(Xapian::docid did, Xapian::valueno slot) const; | |
- void get_all_values(std::map<Xapian::valueno, std::string> & values, | |
+ void get_all_values(values_type& values, | |
Xapian::docid did) const; | |
Xapian::doccount get_value_freq(Xapian::valueno slot) const { | |
diff --git a/src/xapian/backends/inmemory/inmemory_database.cc b/src/xapian/backends/inmemory/inmemory_database.cc | |
index 4f574d398..b79310366 100644 | |
--- a/src/xapian/backends/inmemory/inmemory_database.cc | |
+++ b/src/xapian/backends/inmemory/inmemory_database.cc | |
@@ -666,7 +666,7 @@ InMemoryDatabase::open_position_list(Xapian::docid did, | |
void | |
InMemoryDatabase::add_values(Xapian::docid did, | |
- const map<Xapian::valueno, string> &values_) | |
+ const values_type &values_) | |
{ | |
if (closed) InMemoryDatabase::throw_database_closed(); | |
if (did > valuelists.size()) { | |
@@ -675,7 +675,7 @@ InMemoryDatabase::add_values(Xapian::docid did, | |
valuelists[did - 1] = values_; | |
// Update the statistics. | |
- map<Xapian::valueno, string>::const_iterator j; | |
+ values_type::const_iterator j; | |
for (j = values_.begin(); j != values_.end(); ++j) { | |
std::pair<map<Xapian::valueno, ValueStats>::iterator, bool> i; | |
i = valuestats.insert(make_pair(j->first, ValueStats())); | |
@@ -720,7 +720,7 @@ InMemoryDatabase::delete_document(Xapian::docid did) | |
} | |
termlists[did - 1].is_valid = false; | |
doclists[did - 1] = string(); | |
- map<Xapian::valueno, string>::const_iterator j; | |
+ values_type::const_iterator j; | |
for (j = valuelists[did - 1].begin(); j != valuelists[did - 1].end(); ++j) { | |
map<Xapian::valueno, ValueStats>::iterator i; | |
i = valuestats.find(j->first); | |
@@ -770,7 +770,7 @@ InMemoryDatabase::replace_document(Xapian::docid did, | |
if (closed) InMemoryDatabase::throw_database_closed(); | |
if (doc_exists(did)) { | |
- map<Xapian::valueno, string>::const_iterator j; | |
+ values_type::const_iterator j; | |
for (j = valuelists[did - 1].begin(); j != valuelists[did - 1].end(); ++j) { | |
map<Xapian::valueno, ValueStats>::iterator i; | |
i = valuestats.find(j->first); | |
@@ -842,7 +842,7 @@ void | |
InMemoryDatabase::finish_add_doc(Xapian::docid did, const Xapian::Document &document) | |
{ | |
{ | |
- map<Xapian::valueno, string> values; | |
+ values_type values; | |
Xapian::ValueIterator k = document.values_begin(); | |
for ( ; k != document.values_end(); ++k) { | |
values.insert(make_pair(k.get_valueno(), *k)); | |
diff --git a/src/xapian/backends/inmemory/inmemory_database.h b/src/xapian/backends/inmemory/inmemory_database.h | |
index 677d11456..98e230b8b 100644 | |
--- a/src/xapian/backends/inmemory/inmemory_database.h | |
+++ b/src/xapian/backends/inmemory/inmemory_database.h | |
@@ -25,6 +25,8 @@ | |
#ifndef XAPIAN_INCLUDED_INMEMORY_DATABASE_H | |
#define XAPIAN_INCLUDED_INMEMORY_DATABASE_H | |
+#include "allocators.h" | |
+ | |
#include "xapian/api/leafpostlist.h" | |
#include "xapian/api/smallvector.h" | |
#include "xapian/api/termlist.h" | |
@@ -244,13 +246,15 @@ class InMemoryDocument; | |
* This is a prototype database, mainly used for debugging and testing. | |
*/ | |
class InMemoryDatabase : public Xapian::Database::Internal { | |
+ using values_type = std::map<Xapian::valueno, std::string, std::less<Xapian::valueno>, allocators::memory_pool_allocator<std::pair<const Xapian::valueno, std::string>>>; | |
+ | |
friend class InMemoryAllDocsPostList; | |
friend class InMemoryDocument; | |
map<string, InMemoryTerm> postlists; | |
vector<InMemoryDoc> termlists; | |
vector<std::string> doclists; | |
- vector<std::map<Xapian::valueno, string>> valuelists; | |
+ vector<values_type> valuelists; | |
std::map<Xapian::valueno, ValueStats> valuestats; | |
vector<Xapian::termcount> doclengths; | |
@@ -277,7 +281,7 @@ class InMemoryDatabase : public Xapian::Database::Internal { | |
/* The common parts of add_doc and replace_doc */ | |
void finish_add_doc(Xapian::docid did, const Xapian::Document &document); | |
- void add_values(Xapian::docid did, const map<Xapian::valueno, string> &values_); | |
+ void add_values(Xapian::docid did, const values_type &values_); | |
void make_posting(InMemoryDoc * doc, | |
const string & tname, | |
diff --git a/src/xapian/backends/inmemory/inmemory_document.cc b/src/xapian/backends/inmemory/inmemory_document.cc | |
index 9debb0516..97c9b368e 100644 | |
--- a/src/xapian/backends/inmemory/inmemory_document.cc | |
+++ b/src/xapian/backends/inmemory/inmemory_document.cc | |
@@ -34,8 +34,8 @@ InMemoryDocument::fetch_value(Xapian::valueno slot) const | |
db = static_cast<const InMemoryDatabase*>(database.get()); | |
if (rare(did > db->valuelists.size())) | |
RETURN(string()); | |
- map<Xapian::valueno, string> values_ = db->valuelists[did - 1]; | |
- map<Xapian::valueno, string>::const_iterator i; | |
+ values_type values_ = db->valuelists[did - 1]; | |
+ values_type::const_iterator i; | |
i = values_.find(slot); | |
if (i == values_.end()) | |
RETURN(string()); | |
@@ -43,7 +43,7 @@ InMemoryDocument::fetch_value(Xapian::valueno slot) const | |
} | |
void | |
-InMemoryDocument::fetch_all_values(map<Xapian::valueno, string> &values_) const | |
+InMemoryDocument::fetch_all_values(values_type& values_) const | |
{ | |
LOGCALL_VOID(DB, "InMemoryDocument::fetch_all_values", values_); | |
const InMemoryDatabase * db; | |
diff --git a/src/xapian/backends/inmemory/inmemory_document.h b/src/xapian/backends/inmemory/inmemory_document.h | |
index 107d9b59d..2db3274f7 100644 | |
--- a/src/xapian/backends/inmemory/inmemory_document.h | |
+++ b/src/xapian/backends/inmemory/inmemory_document.h | |
@@ -42,7 +42,7 @@ class InMemoryDocument : public Xapian::Document::Internal { | |
protected: | |
/** Implementation of virtual methods @{ */ | |
string fetch_value(Xapian::valueno slot) const; | |
- void fetch_all_values(map<Xapian::valueno, string> & values_) const; | |
+ void fetch_all_values(values_type& values_) const; | |
string fetch_data() const; | |
/** @} */ | |
}; | |
diff --git a/src/xapian/backends/remote/remote-database.cc b/src/xapian/backends/remote/remote-database.cc | |
index d435e6830..3cefe5681 100644 | |
--- a/src/xapian/backends/remote/remote-database.cc | |
+++ b/src/xapian/backends/remote/remote-database.cc | |
@@ -279,7 +279,7 @@ RemoteDatabase::open_document(Xapian::docid did, bool /*lazy*/) const | |
send_message(MSG_DOCUMENT, encode_length(did)); | |
string doc_data; | |
- map<Xapian::valueno, string> values; | |
+ RemoteDocument::values_type values; | |
get_message(doc_data, REPLY_DOCDATA); | |
string message; | |
diff --git a/src/xapian/backends/remote/remote-document.cc b/src/xapian/backends/remote/remote-document.cc | |
index 2ca82a304..abb6ff0ee 100644 | |
--- a/src/xapian/backends/remote/remote-document.cc | |
+++ b/src/xapian/backends/remote/remote-document.cc | |
@@ -35,7 +35,7 @@ RemoteDocument::fetch_value(Xapian::valueno) const | |
} | |
void | |
-RemoteDocument::fetch_all_values(map<Xapian::valueno, string> &) const | |
+RemoteDocument::fetch_all_values(values_type&) const | |
{ | |
LOGCALL_VOID(DB, "RemoteDocument::fetch_all_values", Literal("[&values_]")); | |
// Our ctor sets the values, so we should never get here. | |
diff --git a/src/xapian/backends/remote/remote-document.h b/src/xapian/backends/remote/remote-document.h | |
index e52bb1aa8..b7baa82b6 100644 | |
--- a/src/xapian/backends/remote/remote-document.h | |
+++ b/src/xapian/backends/remote/remote-document.h | |
@@ -42,13 +42,13 @@ class RemoteDocument : public Xapian::Document::Internal { | |
*/ | |
RemoteDocument(const Xapian::Database::Internal *db, Xapian::docid did_, | |
const string & data_, | |
- map<Xapian::valueno, string>&& values_) | |
+ values_type&& values_) | |
: Xapian::Document::Internal(db, did_, data_, std::move(values_)) {} | |
protected: | |
/** Implementation of virtual methods @{ */ | |
string fetch_value(Xapian::valueno slot) const; | |
- void fetch_all_values(map<Xapian::valueno, string> & values_) const; | |
+ void fetch_all_values(values_type& values_) const; | |
string fetch_data() const; | |
/** @} */ | |
}; | |
diff --git a/src/xapian/matcher/valuestreamdocument.cc b/src/xapian/matcher/valuestreamdocument.cc | |
index 212e67907..e3f8e12b6 100644 | |
--- a/src/xapian/matcher/valuestreamdocument.cc | |
+++ b/src/xapian/matcher/valuestreamdocument.cc | |
@@ -87,7 +87,7 @@ ValueStreamDocument::fetch_value(Xapian::valueno slot) const | |
} | |
void | |
-ValueStreamDocument::fetch_all_values(map<Xapian::valueno, string> & v) const | |
+ValueStreamDocument::fetch_all_values(values_type& v) const | |
{ | |
if (!doc) { | |
doc = database->open_document(did, true); | |
diff --git a/src/xapian/matcher/valuestreamdocument.h b/src/xapian/matcher/valuestreamdocument.h | |
index 42a7d2c0e..a093f08f3 100644 | |
--- a/src/xapian/matcher/valuestreamdocument.h | |
+++ b/src/xapian/matcher/valuestreamdocument.h | |
@@ -91,7 +91,7 @@ class ValueStreamDocument : public Xapian::Document::Internal { | |
protected: | |
/** Implementation of virtual methods @{ */ | |
std::string fetch_value(Xapian::valueno slot) const; | |
- void fetch_all_values(std::map<Xapian::valueno, std::string> & values_) const; | |
+ void fetch_all_values(values_type& values_) const; | |
std::string fetch_data() const; | |
/** @} */ | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment