74
74
#include " llvm/ADT/StringExtras.h"
75
75
#include " llvm/ADT/StringMap.h"
76
76
#include " llvm/ADT/StringSwitch.h"
77
+ #include " llvm/ADT/TinyPtrVector.h"
77
78
#include " llvm/Support/Path.h"
78
79
79
80
#include < algorithm>
@@ -2578,11 +2579,11 @@ namespace {
2578
2579
Impl.addAlternateDecl (subscriptImpl, subscript);
2579
2580
}
2580
2581
2581
- if ( Impl.cxxDereferenceOperators .find (result) !=
2582
- Impl.cxxDereferenceOperators .end ()) {
2582
+ auto getterAndSetterIt = Impl.cxxDereferenceOperators .find (result);
2583
+ if (getterAndSetterIt != Impl.cxxDereferenceOperators .end ()) {
2583
2584
// If this type has a dereference operator, synthesize a computed
2584
2585
// property called `pointee` for it.
2585
- auto getterAndSetter = Impl. cxxDereferenceOperators [result] ;
2586
+ auto getterAndSetter = getterAndSetterIt-> second ;
2586
2587
2587
2588
VarDecl *pointeeProperty =
2588
2589
synthesizer.makeDereferencedPointeeProperty (
@@ -5076,10 +5077,9 @@ namespace {
5076
5077
5077
5078
// Check whether there's some special method to import.
5078
5079
if (!forceClassMethod) {
5079
- if (dc == Impl.importDeclContextOf (decl, decl->getDeclContext ()) &&
5080
- !Impl.ImportedDecls [{decl->getCanonicalDecl (), getVersion ()}])
5081
- Impl.ImportedDecls [{decl->getCanonicalDecl (), getVersion ()}]
5082
- = result;
5080
+ if (dc == Impl.importDeclContextOf (decl, decl->getDeclContext ()))
5081
+ Impl.ImportedDecls .try_emplace (
5082
+ {decl->getCanonicalDecl (), getVersion ()}, result);
5083
5083
5084
5084
if (importedName.isSubscriptAccessor ()) {
5085
5085
// If this was a subscript accessor, try to create a
@@ -7696,8 +7696,8 @@ SwiftDeclConverter::importSubscript(Decl *decl,
7696
7696
7697
7697
// Note that we've created this subscript.
7698
7698
Impl.Subscripts [{getter, setter}] = subscript;
7699
- if (setter && !Impl. Subscripts [{getter, nullptr }] )
7700
- Impl.Subscripts [ {getter, nullptr }] = subscript;
7699
+ if (setter)
7700
+ Impl.Subscripts . try_emplace ( {getter, nullptr }, subscript) ;
7701
7701
7702
7702
// Make the getter/setter methods unavailable.
7703
7703
if (!getter->isUnavailable ())
@@ -8413,11 +8413,12 @@ SourceFile &ClangImporter::Implementation::getClangSwiftAttrSourceFile(
8413
8413
StringRef attributeText,
8414
8414
bool cached
8415
8415
) {
8416
+ ::TinyPtrVector<SourceFile *> *sourceFiles = nullptr ;
8416
8417
if (cached) {
8417
- auto & sourceFiles = ClangSwiftAttrSourceFiles[attributeText];
8418
+ sourceFiles = & ClangSwiftAttrSourceFiles[attributeText];
8418
8419
8419
8420
// Check whether we've already created a source file.
8420
- for (auto sourceFile : sourceFiles) {
8421
+ for (auto sourceFile : * sourceFiles) {
8421
8422
if (sourceFile->getParentModule () == &module )
8422
8423
return *sourceFile;
8423
8424
}
@@ -8443,10 +8444,8 @@ SourceFile &ClangImporter::Implementation::getClangSwiftAttrSourceFile(
8443
8444
auto sourceFile = new (SwiftContext)
8444
8445
SourceFile (module , SourceFileKind::Library, bufferID);
8445
8446
8446
- if (cached) {
8447
- auto &sourceFiles = ClangSwiftAttrSourceFiles[attributeText];
8448
- sourceFiles.push_back (sourceFile);
8449
- }
8447
+ if (cached)
8448
+ sourceFiles->push_back (sourceFile);
8450
8449
8451
8450
return *sourceFile;
8452
8451
}
@@ -9839,9 +9838,9 @@ ClangImporter::Implementation::importDeclContextOf(
9839
9838
// Clang submodule of the declaration.
9840
9839
const clang::Module *declSubmodule = *getClangSubmoduleForDecl (decl);
9841
9840
auto extensionKey = std::make_pair (nominal, declSubmodule);
9842
- auto knownExtension = extensionPoints.find (extensionKey);
9843
- if (knownExtension != extensionPoints. end () )
9844
- return knownExtension-> second ;
9841
+ auto [it, inserted] = extensionPoints.try_emplace (extensionKey, nullptr );
9842
+ if (!inserted )
9843
+ return it-> getSecond () ;
9845
9844
9846
9845
// Create a new extension for this nominal type/Clang submodule pair.
9847
9846
auto ext = ExtensionDecl::create (SwiftContext, SourceLoc (), nullptr , {},
@@ -9854,7 +9853,7 @@ ClangImporter::Implementation::importDeclContextOf(
9854
9853
// Record this extension so we can find it later. We do this early because
9855
9854
// once we've set the member loader, we don't know when the compiler will use
9856
9855
// it and end up back in this method.
9857
- extensionPoints[extensionKey] = ext;
9856
+ it-> getSecond () = ext;
9858
9857
ext->setMemberLoader (this , reinterpret_cast <uintptr_t >(declSubmodule));
9859
9858
9860
9859
if (auto protoDecl = ext->getExtendedProtocolDecl ()) {
0 commit comments