mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 17:11:59 +00:00
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:
parent
0cfb5391d1
commit
0016d214c3
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 <typename TVisitor, typename T>
|
||||
void Reflect(TVisitor& visitor, WithUsr<T>& 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();
|
||||
|
@ -45,9 +45,9 @@ Index_OnIdMapped::Index_OnIdMapped(const std::shared_ptr<ICacheManager>& 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;
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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<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
|
||||
void Reflect(Reader& visitor, IndexInclude& value) {
|
||||
@ -155,6 +168,7 @@ void ReflectHoverAndComments(Reader& visitor, Def& def) {
|
||||
|
||||
template <typename Def>
|
||||
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())
|
||||
|
@ -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<char[]>& value);
|
||||
void Reflect(Writer& visitor, std::unique_ptr<char[]>& 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<T>& 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 <typename T>
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
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>
|
||||
void PushRange(std::queue<T>* dest, const std::vector<T>& to_add) {
|
||||
for (const T& e : to_add)
|
||||
|
2
third_party/loguru
vendored
2
third_party/loguru
vendored
@ -1 +1 @@
|
||||
Subproject commit bead38889d44d9fdb5c52916d1f26c4d6af09e66
|
||||
Subproject commit 37e48808d720194199bc273be4184402a0bc394a
|
Loading…
Reference in New Issue
Block a user