Skip to content

Commit 3a01220

Browse files
committed
Revert use of DenseMap::try_emplace
1 parent 3a0e255 commit 3a01220

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/AST/ClangTypeConverter.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -905,11 +905,17 @@ Decl *ClangTypeConverter::getSwiftDeclForExportedClangDecl(
905905
}
906906

907907
clang::QualType ClangTypeConverter::convertTemplateArgument(Type type) {
908-
auto withCache = [&](auto lookup) {
909-
auto [it, inserted] = Cache.try_emplace(type, clang::QualType{});
910-
if (inserted)
911-
it->second = lookup();
912-
return it->second;
908+
auto withCache = [&](auto conversion) {
909+
auto cached = Cache.find(type);
910+
if (cached != Cache.end())
911+
return cached->second;
912+
913+
// Cache miss; perform the conversion and cache successful results
914+
auto result = conversion();
915+
916+
if (!result.isNull())
917+
Cache.insert({type, result});
918+
return result;
913919
};
914920

915921
// This type was imported from Clang, so we can convert it back by retrieving

0 commit comments

Comments
 (0)