From 4416a258ae111a674212265356c2254ee889cf9a Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 3 Dec 2018 09:42:16 -0800 Subject: [PATCH] query: fix UpdateUses when a new entity is seen; simplify {DeclRef,Use,Usr}Update Thanks to Leszek Swirski --- src/query.cc | 2 +- src/query.hh | 28 ++++++++++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/query.cc b/src/query.cc index 80c6d02a..3c706e84 100644 --- a/src/query.cc +++ b/src/query.cc @@ -252,7 +252,7 @@ void DB::ApplyIndexUpdate(IndexUpdate *u) { auto &entities, auto &p, bool hint_implicit) { auto R = entity_usr.try_emplace(usr, entity_usr.size()); if (R.second) - vars.emplace_back().usr = usr; + entities.emplace_back().usr = usr; auto &entity = entities[R.first->second]; for (Use &use : p.first) { if (hint_implicit && use.role & Role::Implicit) { diff --git a/src/query.hh b/src/query.hh index 49e6558a..c8e3a659 100644 --- a/src/query.hh +++ b/src/query.hh @@ -62,13 +62,9 @@ template struct QueryEntity { } }; -using DeclRefUpdate = - std::unordered_map, std::vector>>; -using UseUpdate = - std::unordered_map, std::vector>>; -using UsrUpdate = - std::unordered_map, std::vector>>; +template +using Update = + std::unordered_map, std::vector>>; struct QueryFunc : QueryEntity { Usr usr; @@ -115,25 +111,25 @@ struct IndexUpdate { int funcs_hint; std::vector> funcs_removed; std::vector> funcs_def_update; - DeclRefUpdate funcs_declarations; - UseUpdate funcs_uses; - UsrUpdate funcs_derived; + Update funcs_declarations; + Update funcs_uses; + Update funcs_derived; // Type updates. int types_hint; std::vector> types_removed; std::vector> types_def_update; - DeclRefUpdate types_declarations; - UseUpdate types_uses; - UsrUpdate types_derived; - UsrUpdate types_instances; + Update types_declarations; + Update types_uses; + Update types_derived; + Update types_instances; // Variable updates. int vars_hint; std::vector> vars_removed; std::vector> vars_def_update; - DeclRefUpdate vars_declarations; - UseUpdate vars_uses; + Update vars_declarations; + Update vars_uses; }; struct DenseMapInfoForUsr {