diff --git a/src/import_pipeline.cc b/src/import_pipeline.cc index 182b9637..985e5c74 100644 --- a/src/import_pipeline.cc +++ b/src/import_pipeline.cc @@ -465,7 +465,7 @@ bool IndexMain_DoCreateIndexUpdate(TimestampManager* timestamp_manager) { LOG_S(INFO) << "Applying IndexUpdate" << std::endl << update.ToString(); #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); return true; @@ -502,7 +502,7 @@ bool IndexMergeIndexUpdates() { did_merge = true; Timer time; - root->update.Merge(to_join->update); + root->update.Merge(std::move(to_join->update)); // time.ResetAndPrint("Joined querydb updates for files: " + // StringJoinMap(root->update.files_def_update, //[](const QueryFile::DefUpdate& update) { diff --git a/src/query.cc b/src/query.cc index 4e18ddfc..9689cc48 100644 --- a/src/query.cc +++ b/src/query.cc @@ -663,7 +663,7 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, } // 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_MERGE(name) AddMergeableRange(&name, update.name); diff --git a/src/query.h b/src/query.h index 8f26efab..9c205307 100644 --- a/src/query.h +++ b/src/query.h @@ -168,7 +168,7 @@ struct MergeableUpdate { std::vector to_remove; MergeableUpdate(TId id, const std::vector& to_add) - : id(id), to_add(to_add) {} + : id(id), to_add(to_add) {} MergeableUpdate(TId id, const std::vector& to_add, const std::vector& to_remove) @@ -189,6 +189,7 @@ struct WithUsr { T value; WithUsr(Usr usr, const T& value) : usr(usr), value(value) {} + WithUsr(Usr usr, T&& value) : usr(usr), value(std::move(value)) {} }; template void Reflect(TVisitor& visitor, WithUsr& value) { @@ -320,7 +321,7 @@ struct IndexUpdate { // Merge |update| into this update; this can reduce overhead / index update // work can be parallelized. - void Merge(const IndexUpdate& update); + void Merge(IndexUpdate&& update); // Dump the update to a string. std::string ToString(); diff --git a/src/queue_manager.cc b/src/queue_manager.cc index d36a796e..5a841708 100644 --- a/src/queue_manager.cc +++ b/src/queue_manager.cc @@ -45,9 +45,9 @@ Index_OnIdMapped::Index_OnIdMapped(const std::shared_ptr& cache_m is_interactive(is_interactive), write_to_disk(write_to_disk) {} -Index_OnIndexed::Index_OnIndexed(IndexUpdate& update, +Index_OnIndexed::Index_OnIndexed(IndexUpdate&& update, PerformanceImportFile perf) - : update(update), perf(perf) {} + : update(std::move(update)), perf(perf) {} QueueManager* QueueManager::instance_ = nullptr; diff --git a/src/queue_manager.h b/src/queue_manager.h index ddd769d3..bc85194f 100644 --- a/src/queue_manager.h +++ b/src/queue_manager.h @@ -76,7 +76,7 @@ struct Index_OnIndexed { IndexUpdate update; PerformanceImportFile perf; - Index_OnIndexed(IndexUpdate& update, PerformanceImportFile perf); + Index_OnIndexed(IndexUpdate&& update, PerformanceImportFile perf); }; struct QueueManager { diff --git a/src/serializer.cc b/src/serializer.cc index a3e81bf9..8b6c7dbc 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -125,6 +125,19 @@ void Reflect(Writer& visitor, std::string_view& data) { visitor.String(&data[0], (rapidjson::SizeType)data.size()); } +void Reflect(Reader& visitor, std::unique_ptr& value) { + if (!visitor.IsString()) + throw std::invalid_argument("std::string"); + std::string t = visitor.GetString(); + value = std::unique_ptr(new char[t.size() + 1]); + strcpy(value.get(), t.c_str()); +} +void Reflect(Writer& visitor, std::unique_ptr& value) { + if (!value) + visitor.String(""); + else + visitor.String(value.get()); +} // TODO: Move this to indexer.cc void Reflect(Reader& visitor, IndexInclude& value) { @@ -155,6 +168,7 @@ void ReflectHoverAndComments(Reader& visitor, Def& def) { template void ReflectHoverAndComments(Writer& visitor, Def& def) { + // Don't emit empty hover and comments in JSON test mode. if (!gTestOutputMode || def.hover.size()) ReflectMember(visitor, "hover", def.hover); if (!gTestOutputMode || def.comments.size()) diff --git a/src/serializer.h b/src/serializer.h index b53aeeb5..714b6c10 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -160,6 +160,9 @@ void Reflect(Writer& visitor, std::string& value); void Reflect(Reader& visitor, std::string_view& view); void Reflect(Writer& visitor, std::string_view& view); +void Reflect(Reader& visitor, std::unique_ptr& value); +void Reflect(Writer& visitor, std::unique_ptr& value); + // std::monostate is used to represent JSON null void Reflect(Reader& visitor, std::monostate&); void Reflect(Writer& visitor, std::monostate&); @@ -303,7 +306,7 @@ void Reflect(Reader& visitor, std::vector& values) { visitor.IterArray([&](Reader& entry) { T entry_value; Reflect(entry, entry_value); - values.push_back(entry_value); + values.push_back(std::move(entry_value)); }); } template diff --git a/src/utils.h b/src/utils.h index 0de383cc..a7fca9f0 100644 --- a/src/utils.h +++ b/src/utils.h @@ -135,6 +135,12 @@ void AddRange(std::vector* dest, const std::vector& to_add) { dest->insert(dest->end(), to_add.begin(), to_add.end()); } +template +void AddRange(std::vector* dest, std::vector&& to_add) { + for (T& x : to_add) + dest->push_back(std::move(x)); +} + template void PushRange(std::queue* dest, const std::vector& to_add) { for (const T& e : to_add) diff --git a/third_party/loguru b/third_party/loguru index bead3888..37e48808 160000 --- a/third_party/loguru +++ b/third_party/loguru @@ -1 +1 @@ -Subproject commit bead38889d44d9fdb5c52916d1f26c4d6af09e66 +Subproject commit 37e48808d720194199bc273be4184402a0bc394a