Skip to content

Commit b5a7658

Browse files
jagillfacebook-github-bot
authored andcommitted
refactor: Reduce unneeded copies (facebookincubator#14058)
Summary: Pull Request resolved: facebookincubator#14058 Lint identified several places where we are implicitly copying variables. Replace these patterns with ones that don't copy. Also reserve a vector to reduce unnecessary allocations. Reviewed By: xiaoxmeng Differential Revision: D78016694 fbshipit-source-id: 42b9ae914c4f06e3e41edaaaceb6c6b406cc55c0
1 parent d36b25c commit b5a7658

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

velox/core/PlanNode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,14 +1265,14 @@ AbstractJoinNode::AbstractJoinNode(
12651265
rightKeys_.size(),
12661266
"JoinNode requires same number of join keys on left and right sides");
12671267
auto leftType = sources_[0]->outputType();
1268-
for (auto key : leftKeys_) {
1268+
for (const auto& key : leftKeys_) {
12691269
VELOX_CHECK(
12701270
leftType->containsChild(key->name()),
12711271
"Left side join key not found in left side output: {}",
12721272
key->name());
12731273
}
12741274
auto rightType = sources_[1]->outputType();
1275-
for (auto key : rightKeys_) {
1275+
for (const auto& key : rightKeys_) {
12761276
VELOX_CHECK(
12771277
rightType->containsChild(key->name()),
12781278
"Right side join key not found in right side output: {}",

velox/core/PlanNode.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct PlanSummaryOptions {
162162

163163
class PlanNode : public ISerializable {
164164
public:
165-
explicit PlanNode(const PlanNodeId& id) : id_{id} {}
165+
explicit PlanNode(PlanNodeId id) : id_{std::move(id)} {}
166166

167167
virtual ~PlanNode() {}
168168

@@ -822,6 +822,7 @@ class AbstractProjectNode : public PlanNode {
822822
const std::vector<std::string>& names,
823823
const std::vector<TypedExprPtr>& projections) {
824824
std::vector<TypePtr> types;
825+
types.reserve(projections.size());
825826
for (auto& projection : projections) {
826827
types.push_back(projection->type());
827828
}

0 commit comments

Comments
 (0)