Convert copy constructor to move constructors piecemeal

If I replace all the important constructors used in query.cc, there will be a weird issue that strings following "Applying index update for " are empty.
This commit is contained in:
Fangrui Song 2018-02-05 23:22:44 -08:00
parent 0cfb5391d1
commit 0016d214c3
9 changed files with 34 additions and 10 deletions

View File

@ -465,7 +465,7 @@ bool IndexMain_DoCreateIndexUpdate(TimestampManager* timestamp_manager) {
LOG_S(INFO) << "Applying IndexUpdate" << std::endl << update.ToString(); LOG_S(INFO) << "Applying IndexUpdate" << std::endl << update.ToString();
#endif #endif
Index_OnIndexed reply(update, response->perf); Index_OnIndexed reply(std::move(update), response->perf);
queue->on_indexed.PushBack(std::move(reply), response->is_interactive); queue->on_indexed.PushBack(std::move(reply), response->is_interactive);
return true; return true;
@ -502,7 +502,7 @@ bool IndexMergeIndexUpdates() {
did_merge = true; did_merge = true;
Timer time; Timer time;
root->update.Merge(to_join->update); root->update.Merge(std::move(to_join->update));
// time.ResetAndPrint("Joined querydb updates for files: " + // time.ResetAndPrint("Joined querydb updates for files: " +
// StringJoinMap(root->update.files_def_update, // StringJoinMap(root->update.files_def_update,
//[](const QueryFile::DefUpdate& update) { //[](const QueryFile::DefUpdate& update) {

View File

@ -663,7 +663,7 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map,
} }
// This function runs on an indexer thread. // This function runs on an indexer thread.
void IndexUpdate::Merge(const IndexUpdate& update) { void IndexUpdate::Merge(IndexUpdate&& update) {
#define INDEX_UPDATE_APPEND(name) AddRange(&name, update.name); #define INDEX_UPDATE_APPEND(name) AddRange(&name, update.name);
#define INDEX_UPDATE_MERGE(name) AddMergeableRange(&name, update.name); #define INDEX_UPDATE_MERGE(name) AddMergeableRange(&name, update.name);

View File

@ -189,6 +189,7 @@ struct WithUsr {
T value; T value;
WithUsr(Usr usr, const T& value) : usr(usr), value(value) {} WithUsr(Usr usr, const T& value) : usr(usr), value(value) {}
WithUsr(Usr usr, T&& value) : usr(usr), value(std::move(value)) {}
}; };
template <typename TVisitor, typename T> template <typename TVisitor, typename T>
void Reflect(TVisitor& visitor, WithUsr<T>& value) { void Reflect(TVisitor& visitor, WithUsr<T>& value) {
@ -320,7 +321,7 @@ struct IndexUpdate {
// Merge |update| into this update; this can reduce overhead / index update // Merge |update| into this update; this can reduce overhead / index update
// work can be parallelized. // work can be parallelized.
void Merge(const IndexUpdate& update); void Merge(IndexUpdate&& update);
// Dump the update to a string. // Dump the update to a string.
std::string ToString(); std::string ToString();

View File

@ -45,9 +45,9 @@ Index_OnIdMapped::Index_OnIdMapped(const std::shared_ptr<ICacheManager>& cache_m
is_interactive(is_interactive), is_interactive(is_interactive),
write_to_disk(write_to_disk) {} write_to_disk(write_to_disk) {}
Index_OnIndexed::Index_OnIndexed(IndexUpdate& update, Index_OnIndexed::Index_OnIndexed(IndexUpdate&& update,
PerformanceImportFile perf) PerformanceImportFile perf)
: update(update), perf(perf) {} : update(std::move(update)), perf(perf) {}
QueueManager* QueueManager::instance_ = nullptr; QueueManager* QueueManager::instance_ = nullptr;

View File

@ -76,7 +76,7 @@ struct Index_OnIndexed {
IndexUpdate update; IndexUpdate update;
PerformanceImportFile perf; PerformanceImportFile perf;
Index_OnIndexed(IndexUpdate& update, PerformanceImportFile perf); Index_OnIndexed(IndexUpdate&& update, PerformanceImportFile perf);
}; };
struct QueueManager { struct QueueManager {

View File

@ -125,6 +125,19 @@ void Reflect(Writer& visitor, std::string_view& data) {
visitor.String(&data[0], (rapidjson::SizeType)data.size()); visitor.String(&data[0], (rapidjson::SizeType)data.size());
} }
void Reflect(Reader& visitor, std::unique_ptr<char[]>& value) {
if (!visitor.IsString())
throw std::invalid_argument("std::string");
std::string t = visitor.GetString();
value = std::unique_ptr<char[]>(new char[t.size() + 1]);
strcpy(value.get(), t.c_str());
}
void Reflect(Writer& visitor, std::unique_ptr<char[]>& value) {
if (!value)
visitor.String("");
else
visitor.String(value.get());
}
// TODO: Move this to indexer.cc // TODO: Move this to indexer.cc
void Reflect(Reader& visitor, IndexInclude& value) { void Reflect(Reader& visitor, IndexInclude& value) {
@ -155,6 +168,7 @@ void ReflectHoverAndComments(Reader& visitor, Def& def) {
template <typename Def> template <typename Def>
void ReflectHoverAndComments(Writer& visitor, Def& def) { void ReflectHoverAndComments(Writer& visitor, Def& def) {
// Don't emit empty hover and comments in JSON test mode.
if (!gTestOutputMode || def.hover.size()) if (!gTestOutputMode || def.hover.size())
ReflectMember(visitor, "hover", def.hover); ReflectMember(visitor, "hover", def.hover);
if (!gTestOutputMode || def.comments.size()) if (!gTestOutputMode || def.comments.size())

View File

@ -160,6 +160,9 @@ void Reflect(Writer& visitor, std::string& value);
void Reflect(Reader& visitor, std::string_view& view); void Reflect(Reader& visitor, std::string_view& view);
void Reflect(Writer& visitor, std::string_view& view); void Reflect(Writer& visitor, std::string_view& view);
void Reflect(Reader& visitor, std::unique_ptr<char[]>& value);
void Reflect(Writer& visitor, std::unique_ptr<char[]>& value);
// std::monostate is used to represent JSON null // std::monostate is used to represent JSON null
void Reflect(Reader& visitor, std::monostate&); void Reflect(Reader& visitor, std::monostate&);
void Reflect(Writer& visitor, std::monostate&); void Reflect(Writer& visitor, std::monostate&);
@ -303,7 +306,7 @@ void Reflect(Reader& visitor, std::vector<T>& values) {
visitor.IterArray([&](Reader& entry) { visitor.IterArray([&](Reader& entry) {
T entry_value; T entry_value;
Reflect(entry, entry_value); Reflect(entry, entry_value);
values.push_back(entry_value); values.push_back(std::move(entry_value));
}); });
} }
template <typename T> template <typename T>

View File

@ -135,6 +135,12 @@ void AddRange(std::vector<T>* dest, const std::vector<T>& to_add) {
dest->insert(dest->end(), to_add.begin(), to_add.end()); dest->insert(dest->end(), to_add.begin(), to_add.end());
} }
template <typename T>
void AddRange(std::vector<T>* dest, std::vector<T>&& to_add) {
for (T& x : to_add)
dest->push_back(std::move(x));
}
template <typename T> template <typename T>
void PushRange(std::queue<T>* dest, const std::vector<T>& to_add) { void PushRange(std::queue<T>* dest, const std::vector<T>& to_add) {
for (const T& e : to_add) for (const T& e : to_add)

2
third_party/loguru vendored

@ -1 +1 @@
Subproject commit bead38889d44d9fdb5c52916d1f26c4d6af09e66 Subproject commit 37e48808d720194199bc273be4184402a0bc394a