@@ -206,16 +206,14 @@ matchTemplate(const std::string &template_str,
206206 }
207207 nextLit = template_str.substr (ti, scan - ti);
208208
209- auto it = captured.find ( name);
210- if (it != captured. end () ) {
209+ auto [it, inserted] = captured.try_emplace ( std::move ( name) );
210+ if (!inserted ) {
211211 size_t end_pos = 0 ;
212212 if (!matchLiteralAt (instantiated, si, it->second , end_pos)) {
213213 return std::nullopt ;
214214 }
215215 si = end_pos;
216216 } else {
217- std::string value;
218-
219217 if (!nextLit.empty ()) {
220218 size_t k = findNextLiteralSameDepth (instantiated, si, nextLit);
221219 if (k == std::string::npos) {
@@ -232,7 +230,7 @@ matchTemplate(const std::string &template_str,
232230 b--;
233231 }
234232
235- value = instantiated.substr (a, b - a);
233+ it-> second = instantiated.substr (a, b - a);
236234 si = k;
237235 } else {
238236 size_t a = si;
@@ -245,11 +243,9 @@ matchTemplate(const std::string &template_str,
245243 b--;
246244 }
247245
248- value = instantiated.substr (a, b - a);
246+ it-> second = instantiated.substr (a, b - a);
249247 si = instantiated.size ();
250248 }
251-
252- captured[name] = value;
253249 }
254250
255251 if (!nextLit.empty ()) {
@@ -676,12 +672,11 @@ void AddRuleForUserDefinedType(clang::NamedDecl *decl) {
676672 auto cpp_name = ToString (decl);
677673 auto rs_name = ReplaceAll (cpp_name, " ::" , " _" );
678674
679- if (types_.contains (cpp_name)) {
675+ if (!types_.try_emplace (cpp_name, TranslationRule::TypeTgt::Plain (rs_name))
676+ .second ) {
680677 return ;
681678 }
682679
683- types_[cpp_name] = TranslationRule::TypeTgt::Plain (rs_name);
684-
685680 if (auto record_decl = llvm::dyn_cast<clang::RecordDecl>(decl)) {
686681 // Forward declaration
687682 if (!record_decl->isThisDeclarationADefinition ()) {
0 commit comments