Skip to content

Commit 0d3833e

Browse files
committed
Eliminate double Cache lookup using try_emplace
1 parent 75a1daa commit 0d3833e

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

lib/AST/ClangTypeConverter.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -905,14 +905,10 @@ clang::QualType ClangTypeConverter::convertTemplateArgument(Type type) {
905905
// a handful of Swift builtin types. These are enumerated here rather than
906906
// delegated to ClangTypeConverter::convert() (which is more general).
907907
auto withCache = [&](auto lookup) {
908-
auto cached = Cache.find(type);
909-
if (cached != Cache.end())
910-
return cached->second;
911-
912-
auto result = lookup();
913-
if (!result.isNull())
914-
Cache.insert({type, result});
915-
return result;
908+
auto [it, inserted] = Cache.try_emplace(type, clang::QualType{});
909+
if (!inserted)
910+
it->second = lookup();
911+
return it->second;
916912
};
917913

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

0 commit comments

Comments
 (0)