Convert some copy constructors to move constructors in query.cc

This commit is contained in:
Fangrui Song 2018-02-06 21:45:58 -08:00
parent 55c7519e93
commit e440a7c52f
3 changed files with 12 additions and 12 deletions

View File

@ -100,7 +100,7 @@ optional<QueryVar::Def> ToQuery(const IdMap& id_map, const IndexVar::Def& var) {
template <typename TId, typename TValue>
void AddMergeableRange(
std::vector<MergeableUpdate<TId, TValue>>* dest,
const std::vector<MergeableUpdate<TId, TValue>>& source) {
std::vector<MergeableUpdate<TId, TValue>>&& source) {
// TODO: Consider caching the lookup table. It can probably save even more
// time at the cost of some additional memory.
@ -111,13 +111,13 @@ void AddMergeableRange(
id_to_index[(*dest)[i].id] = i;
// Add entries. Try to add them to an existing entry.
for (const auto& entry : source) {
for (auto& entry : source) {
auto it = id_to_index.find(entry.id);
if (it != id_to_index.end()) {
AddRange(&(*dest)[it->second].to_add, entry.to_add);
AddRange(&(*dest)[it->second].to_remove, entry.to_remove);
AddRange(&(*dest)[it->second].to_add, std::move(entry.to_add));
AddRange(&(*dest)[it->second].to_remove, std::move(entry.to_remove));
} else {
dest->push_back(entry);
dest->push_back(std::move(entry));
}
}
}
@ -664,8 +664,8 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map,
// This function runs on an indexer thread.
void IndexUpdate::Merge(IndexUpdate&& update) {
#define INDEX_UPDATE_APPEND(name) AddRange(&name, update.name);
#define INDEX_UPDATE_MERGE(name) AddMergeableRange(&name, update.name);
#define INDEX_UPDATE_APPEND(name) AddRange(&name, std::move(update.name));
#define INDEX_UPDATE_MERGE(name) AddMergeableRange(&name, std::move(update.name));
INDEX_UPDATE_APPEND(files_removed);
INDEX_UPDATE_APPEND(files_def_update);

View File

@ -185,7 +185,7 @@ void Reflect(Reader& visitor, optional<T>& value) {
}
T real_value;
Reflect(visitor, real_value);
value = real_value;
value = std::move(real_value);
}
template <typename T>
void Reflect(Writer& visitor, optional<T>& value) {
@ -204,7 +204,7 @@ void Reflect(Reader& visitor, Maybe<T>& value) {
}
T real_value;
Reflect(visitor, real_value);
value = real_value;
value = std::move(real_value);
}
template <typename T>
void Reflect(Writer& visitor, Maybe<T>& value) {
@ -254,7 +254,7 @@ struct ReflectVariant {
ReflectTag(Reader& visitor, std::variant<Ts...>& value) {
T a;
Reflect(visitor, a);
value = a;
value = std::move(a);
}
// This SFINAE overload is used to prevent compile error. value = a; is not
// allowed if T does not appear in Ts...

View File

@ -137,8 +137,8 @@ void AddRange(std::vector<T>* dest, const std::vector<T>& to_add) {
template <typename T>
void AddRange(std::vector<T>* dest, std::vector<T>&& to_add) {
dest->push_back(dest->end(), std::make_move_iterator(to_add.begin()),
std::make_move_iterator(to_add.end()));
dest->insert(dest->end(), std::make_move_iterator(to_add.begin()),
std::make_move_iterator(to_add.end()));
}
template <typename T>