@@ -37,23 +37,16 @@ std::unordered_multimap<RuleDecls::ExprKey, ExprRuleDecl,
3737 exprs_;
3838std::unordered_multimap<const void *, TypeRuleDecl> types_;
3939
40- const llvm::json::Object &unsafeIndex () {
41- static const llvm::json::Object index = RulesLoader::ReadIndex (
42- std::filesystem::path (RULES_INDEX_DIR ) / " index_unsafe.json" );
43- return index;
44- }
45-
46- const llvm::json::Object &refcountIndex () {
47- static const llvm::json::Object index = RulesLoader::ReadIndex (
48- std::filesystem::path (RULES_INDEX_DIR ) / " index_refcount.json" );
49- return index;
50- }
51-
52- const llvm::json::Object *findRule (const llvm::json::Object &index,
53- const std::string &dir,
40+ const llvm::json::Object *findRule (Model model, const std::string &dir,
5441 const std::string &name) {
55- auto rules = index.getObject (dir);
56- return rules ? rules->getObject (name) : nullptr ;
42+ static std::unordered_map<std::string, llvm::json::Object> indexes;
43+ auto path = std::filesystem::path (RULES_IR_DIR ) / dir /
44+ (model == Model::kRefCount ? " ir_refcount.json" : " ir_unsafe.json" );
45+ auto [it, inserted] = indexes.try_emplace (path.string ());
46+ if (inserted && std::filesystem::exists (path)) {
47+ it->second = RulesLoader::ReadIndex (path);
48+ }
49+ return it->second .getObject (name);
5750}
5851
5952bool pointsToUserType (clang::QualType type) {
@@ -114,9 +107,9 @@ void checkGenerics(const std::string &dir, const std::string &name,
114107
115108void addRule (clang::ASTContext &ctx, const std::string &dir,
116109 const std::string &name, const clang::NamedDecl *decl) {
117- auto rule = findRule (unsafeIndex () , dir, name);
110+ auto rule = findRule (Model:: kUnsafe , dir, name);
118111 if (model_ == Model::kRefCount ) {
119- if (auto refcount_rule = findRule (refcountIndex () , dir, name)) {
112+ if (auto refcount_rule = findRule (model_ , dir, name)) {
120113 rule = refcount_rule;
121114 }
122115 }
0 commit comments