Skip to content

Commit

Permalink
Optimization: avoid copying the whole "seen" set
Browse files Browse the repository at this point in the history
by dropping the last value instead

PiperOrigin-RevId: 652888920
  • Loading branch information
oprypin authored and copybara-github committed Jul 16, 2024
1 parent 69e55b3 commit 5f8a939
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pytype/typegraph/solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,11 @@ bool Solver::RecallOrFindSolution(
// that if it's possible to solve this state at this level of the tree, it can
// also be solved in any of the children.
(*solved_states_)[state] = true;
// Careful! Modifying seen_states would affect other recursive calls, so we
// need to copy it.
internal::StateSet new_seen_states(seen_states);
new_seen_states.insert(&state);

bool result = FindSolution(state, new_seen_states, current_depth);
// Careful! Make sure to remove the value from seen_states afterwards, to not
// affect other recursive calls.
seen_states.insert(&state);
bool result = FindSolution(state, seen_states, current_depth);
seen_states.erase(&state);
(*solved_states_)[state] = result;
return result;
}
Expand Down

0 comments on commit 5f8a939

Please sign in to comment.