From 19e5e36ac672089115ba65498ccfcbfbb4ab3851 Mon Sep 17 00:00:00 2001 From: "jie.wang" <38901892+jievince@users.noreply.github.com> Date: Fri, 23 Jul 2021 14:05:12 +0800 Subject: [PATCH] eliminate one copy in ExtractList of UnwindExecutor (#1276) Co-authored-by: Yee <2520865+yixinglu@users.noreply.github.com> --- src/executor/query/UnwindExecutor.cpp | 11 ++++------- src/executor/query/UnwindExecutor.h | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/executor/query/UnwindExecutor.cpp b/src/executor/query/UnwindExecutor.cpp index 952175172..1a4a2adaf 100644 --- a/src/executor/query/UnwindExecutor.cpp +++ b/src/executor/query/UnwindExecutor.cpp @@ -26,7 +26,7 @@ folly::Future UnwindExecutor::execute() { DataSet ds; ds.colNames = unwind->colNames(); for (; iter->valid(); iter->next()) { - Value list = unwindExpr->eval(ctx(iter.get())); + const Value& list = unwindExpr->eval(ctx(iter.get())); std::vector vals = extractList(list); for (auto &v : vals) { Row row; @@ -41,17 +41,14 @@ folly::Future UnwindExecutor::execute() { return finish(ResultBuilder().value(Value(std::move(ds))).finish()); } -std::vector UnwindExecutor::extractList(Value &val) { +std::vector UnwindExecutor::extractList(const Value &val) { std::vector ret; if (val.isList()) { auto &list = val.getList(); - ret.reserve(list.size()); - for (size_t i = 0; i < list.size(); ++i) { - ret.emplace_back(std::move(list[i])); - } + ret = list.values; } else { if (!(val.isNull() || val.empty())) { - ret.emplace_back(std::move(val)); + ret.push_back(val); } } diff --git a/src/executor/query/UnwindExecutor.h b/src/executor/query/UnwindExecutor.h index 06eeebbf9..3e8f81367 100644 --- a/src/executor/query/UnwindExecutor.h +++ b/src/executor/query/UnwindExecutor.h @@ -20,7 +20,7 @@ class UnwindExecutor final : public Executor { folly::Future execute() override; private: - std::vector extractList(Value &val); + std::vector extractList(const Value &val); }; } // namespace graph