diff --git a/pytype/typegraph/map_util.h b/pytype/typegraph/map_util.h index b59cb9c81..d8fe9ccc6 100644 --- a/pytype/typegraph/map_util.h +++ b/pytype/typegraph/map_util.h @@ -41,16 +41,6 @@ bool ContainsKey(const M& map, const K& key) { return map.find(key) != map.end(); } -// FindOrNull returns a pointer to the value associated with the -// given key if it exists, or nullptr otherwise. -template -const V* FindOrNull(const M& map, const K& key) { - auto it = map.find(key); - if (it != map.end()) - return &(it->second); - return nullptr; -} - // FindPtrOrNull returns the pointer value associated with a given key. It is // designed to be used with maps of keys to pointers. It does not differentiate // between keys that are not in the map and keys that are mapped to nullptr. diff --git a/pytype/typegraph/map_util_test.cc b/pytype/typegraph/map_util_test.cc index c82637aaf..7f810273d 100644 --- a/pytype/typegraph/map_util_test.cc +++ b/pytype/typegraph/map_util_test.cc @@ -16,15 +16,6 @@ TEST(MapUtilTest, ContainsKeyTest) { EXPECT_FALSE(ContainsKey(m, 2)); } -TEST(MapUtilTest, FindOrNullTest) { - std::unordered_map m; - EXPECT_EQ(FindOrNull(m, 1), nullptr); - m[1] = true; - const bool* res = FindOrNull(m, 1); - EXPECT_NE(res, nullptr); - EXPECT_EQ(*res, true); -} - TEST(MapUtilTest, FindPtrOrNullTest) { std::unordered_map m; EXPECT_EQ(FindPtrOrNull(m, 1), nullptr); diff --git a/pytype/typegraph/solver.cc b/pytype/typegraph/solver.cc index 85e1479cf..77b3cc04d 100644 --- a/pytype/typegraph/solver.cc +++ b/pytype/typegraph/solver.cc @@ -421,17 +421,17 @@ bool Solver::CanHaveSolution( bool Solver::RecallOrFindSolution( const internal::State& state, internal::StateSet& seen_states, int current_depth) { - const bool* status = map_util::FindOrNull(solved_states_, state); - if (status) { + auto it = solved_states_.find(state); + if (it != solved_states_.end()) { state_cache_hits_ += 1; query_metrics_.back().set_from_cache(true); std::string indent(current_depth, ' '); - if (*status) { + if (it->second) { LOG(INFO) << indent << "Known state: solvable."; } else { LOG(INFO) << indent << "Known state: not solvable."; } - return *status; + return it->second; } else { state_cache_misses_ += 1; }