Skip to content

Commit

Permalink
Update constructors so they don't cause unnecessary copies
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 707455962
  • Loading branch information
oprypin authored and copybara-github committed Dec 18, 2024
1 parent dcd750f commit 2a200be
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pytype/typegraph/solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ namespace internal {
struct RemoveResult {
const GoalSet removed_goals;
const GoalSet new_goals;
RemoveResult(const GoalSet& removed_goals, const GoalSet& new_goals):
removed_goals(removed_goals), new_goals(new_goals) {}
RemoveResult(GoalSet removed_goals, GoalSet new_goals)
: removed_goals(std::move(removed_goals)),
new_goals(std::move(new_goals)) {}
};

struct TraverseState {
Expand All @@ -39,10 +40,10 @@ struct TraverseState {
TraverseState() {}
TraverseState(GoalSet goals_to_remove, GoalSet seen_goals,
GoalSet removed_goals, GoalSet new_goals)
: goals_to_remove(goals_to_remove),
seen_goals(seen_goals),
removed_goals(removed_goals),
new_goals(new_goals) {}
: goals_to_remove(std::move(goals_to_remove)),
seen_goals(std::move(seen_goals)),
removed_goals(std::move(removed_goals)),
new_goals(std::move(new_goals)) {}
};

// Remove all goals that can be fulfilled at the current CFG node.
Expand All @@ -65,7 +66,7 @@ static std::vector<RemoveResult> remove_finished_goals(const CFGNode* pos,
std::inserter(state.new_goals, state.new_goals.begin()),
pointer_less<Binding>());
std::deque<TraverseState> queue;
queue.emplace_back(state);
queue.push_back(std::move(state));
std::vector<RemoveResult> results;
while (!queue.empty()) {
state = std::move(queue.front());
Expand Down

0 comments on commit 2a200be

Please sign in to comment.