From 13795c89933a95d7985428032c610da9c05fdc95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Benjamin=20Antal?= Date: Wed, 1 Mar 2023 08:20:03 +0100 Subject: [PATCH] Small moves here and there --- src/storage/v3/expr.cpp | 6 +++--- src/storage/v3/request_helper.hpp | 4 ++-- src/storage/v3/shard_rsm.cpp | 12 +++++++----- src/storage/v3/value_conversions.hpp | 13 ++++++++++++- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/storage/v3/expr.cpp b/src/storage/v3/expr.cpp index 36c0ff8e3..185e4e29e 100644 --- a/src/storage/v3/expr.cpp +++ b/src/storage/v3/expr.cpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// Copyright 2023 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -35,7 +35,7 @@ msgs::Value ConstructValueVertex(const VertexAccessor &acc, View view) { memgraph::msgs::Label value_label{.id = prim_label}; auto prim_key = conversions::ConvertValueVector(acc.PrimaryKey(view).GetValue()); - memgraph::msgs::VertexId vertex_id = std::make_pair(value_label, prim_key); + memgraph::msgs::VertexId vertex_id = std::make_pair(value_label, std::move(prim_key)); // Get the labels auto vertex_labels = acc.Labels(view).GetValue(); @@ -45,7 +45,7 @@ msgs::Value ConstructValueVertex(const VertexAccessor &acc, View view) { std::transform(vertex_labels.begin(), vertex_labels.end(), std::back_inserter(value_labels), [](const auto &label) { return msgs::Label{.id = label}; }); - return msgs::Value({.id = vertex_id, .labels = value_labels}); + return msgs::Value({.id = std::move(vertex_id), .labels = std::move(value_labels)}); } msgs::Value ConstructValueEdge(const EdgeAccessor &acc, View view) { diff --git a/src/storage/v3/request_helper.hpp b/src/storage/v3/request_helper.hpp index bbe4894e9..5590f93ac 100644 --- a/src/storage/v3/request_helper.hpp +++ b/src/storage/v3/request_helper.hpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// Copyright 2023 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -233,7 +233,7 @@ ShardResult> CollectAllPropertiesImpl(const TAccesso [](std::pair &pair) { return std::make_pair(pair.first, conversions::FromPropertyValueToValue(std::move(pair.second))); }); - return ret; + return {std::move(ret)}; } } // namespace impl diff --git a/src/storage/v3/shard_rsm.cpp b/src/storage/v3/shard_rsm.cpp index 881796a70..72ee07f15 100644 --- a/src/storage/v3/shard_rsm.cpp +++ b/src/storage/v3/shard_rsm.cpp @@ -472,7 +472,8 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::ExpandOneRequest &&req) { if (req.order_by_edges.empty()) { const auto *schema = shard_->GetSchema(shard_->PrimaryLabel()); MG_ASSERT(schema); - return GetExpandOneResult(acc, src_vertex, req, maybe_filter_based_on_edge_uniqueness, edge_filler, *schema); + return GetExpandOneResult(acc, std::move(src_vertex), req, maybe_filter_based_on_edge_uniqueness, edge_filler, + *schema); } auto [in_edge_accessors, out_edge_accessors] = GetEdgesFromVertex(src_vertex_acc, req.direction); const auto in_ordered_edges = OrderByEdges(dba, in_edge_accessors, req.order_by_edges, src_vertex_acc); @@ -487,8 +488,9 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::ExpandOneRequest &&req) { [](const auto &edge_element) { return edge_element.object_acc; }); const auto *schema = shard_->GetSchema(shard_->PrimaryLabel()); MG_ASSERT(schema); - return GetExpandOneResult(src_vertex_acc, src_vertex, req, in_edge_ordered_accessors, out_edge_ordered_accessors, - maybe_filter_based_on_edge_uniqueness, edge_filler, *schema); + return GetExpandOneResult(src_vertex_acc, std::move(src_vertex), req, in_edge_ordered_accessors, + out_edge_ordered_accessors, maybe_filter_based_on_edge_uniqueness, edge_filler, + *schema); }); if (maybe_result.HasError()) { @@ -581,12 +583,12 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::GetPropertiesRequest &&req) { if (maybe_id.HasError()) { return {maybe_id.GetError()}; } - const auto &id = maybe_id.GetValue(); + auto &vertex_id = maybe_id.GetValue(); std::optional e_id; if (e_acc) { e_id = msgs::EdgeId{e_acc->Gid().AsUint()}; } - msgs::VertexId v_id{msgs::Label{id.primary_label}, ConvertValueVector(id.primary_key)}; + msgs::VertexId v_id{msgs::Label{vertex_id.primary_label}, ConvertValueVector(std::move(vertex_id.primary_key))}; auto maybe_props = collect_props(v_acc, e_acc); if (maybe_props.HasError()) { return {maybe_props.GetError()}; diff --git a/src/storage/v3/value_conversions.hpp b/src/storage/v3/value_conversions.hpp index 53374e1ed..c068378ed 100644 --- a/src/storage/v3/value_conversions.hpp +++ b/src/storage/v3/value_conversions.hpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// Copyright 2023 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -126,6 +126,17 @@ inline std::vector ConvertValueVector(const std::vector ConvertValueVector(std::vector &&vec) { + std::vector ret; + ret.reserve(vec.size()); + + for (auto &&elem : vec) { + ret.push_back(FromPropertyValueToValue(std::move(elem))); + } + + return ret; +} + inline msgs::VertexId ToMsgsVertexId(const v3::VertexId &vertex_id) { return {msgs::Label{vertex_id.primary_label}, ConvertValueVector(vertex_id.primary_key)}; }