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>
@@ -2574,11 +2575,11 @@ namespace {
2574
2575
Impl.addAlternateDecl (subscriptImpl, subscript);
2575
2576
}
2576
2577
2577
- if ( Impl.cxxDereferenceOperators .find (result) !=
2578
- Impl.cxxDereferenceOperators .end ()) {
2578
+ auto getterAndSetterIt = Impl.cxxDereferenceOperators .find (result);
2579
+ if (getterAndSetterIt != Impl.cxxDereferenceOperators .end ()) {
2579
2580
// If this type has a dereference operator, synthesize a computed
2580
2581
// property called `pointee` for it.
2581
- auto getterAndSetter = Impl. cxxDereferenceOperators [result] ;
2582
+ auto getterAndSetter = getterAndSetterIt-> second ;
2582
2583
2583
2584
VarDecl *pointeeProperty =
2584
2585
synthesizer.makeDereferencedPointeeProperty (
@@ -5119,10 +5120,9 @@ namespace {
5119
5120
5120
5121
// Check whether there's some special method to import.
5121
5122
if (!forceClassMethod) {
5122
- if (dc == Impl.importDeclContextOf (decl, decl->getDeclContext ()) &&
5123
- !Impl.ImportedDecls [{decl->getCanonicalDecl (), getVersion ()}])
5124
- Impl.ImportedDecls [{decl->getCanonicalDecl (), getVersion ()}]
5125
- = result;
5123
+ if (dc == Impl.importDeclContextOf (decl, decl->getDeclContext ()))
5124
+ Impl.ImportedDecls .try_emplace (
5125
+ {decl->getCanonicalDecl (), getVersion ()}, result);
5126
5126
5127
5127
if (importedName.isSubscriptAccessor ()) {
5128
5128
// If this was a subscript accessor, try to create a
@@ -7780,8 +7780,8 @@ SwiftDeclConverter::importSubscript(Decl *decl,
7780
7780
7781
7781
// Note that we've created this subscript.
7782
7782
Impl.Subscripts [{getter, setter}] = subscript;
7783
- if (setter && !Impl. Subscripts [{getter, nullptr }] )
7784
- Impl.Subscripts [ {getter, nullptr }] = subscript;
7783
+ if (setter)
7784
+ Impl.Subscripts . try_emplace ( {getter, nullptr }, subscript) ;
7785
7785
7786
7786
// Make the getter/setter methods unavailable.
7787
7787
if (!getter->isUnavailable ())
@@ -8497,11 +8497,12 @@ SourceFile &ClangImporter::Implementation::getClangSwiftAttrSourceFile(
8497
8497
StringRef attributeText,
8498
8498
bool cached
8499
8499
) {
8500
+ ::TinyPtrVector<SourceFile *> *sourceFiles = nullptr ;
8500
8501
if (cached) {
8501
- auto & sourceFiles = ClangSwiftAttrSourceFiles[attributeText];
8502
+ sourceFiles = & ClangSwiftAttrSourceFiles[attributeText];
8502
8503
8503
8504
// Check whether we've already created a source file.
8504
- for (auto sourceFile : sourceFiles) {
8505
+ for (auto sourceFile : * sourceFiles) {
8505
8506
if (sourceFile->getParentModule () == &module )
8506
8507
return *sourceFile;
8507
8508
}
@@ -8527,10 +8528,8 @@ SourceFile &ClangImporter::Implementation::getClangSwiftAttrSourceFile(
8527
8528
auto sourceFile = new (SwiftContext)
8528
8529
SourceFile (module , SourceFileKind::Library, bufferID);
8529
8530
8530
- if (cached) {
8531
- auto &sourceFiles = ClangSwiftAttrSourceFiles[attributeText];
8532
- sourceFiles.push_back (sourceFile);
8533
- }
8531
+ if (cached)
8532
+ sourceFiles->push_back (sourceFile);
8534
8533
8535
8534
return *sourceFile;
8536
8535
}
@@ -9880,9 +9879,9 @@ ClangImporter::Implementation::importDeclContextOf(
9880
9879
// Clang submodule of the declaration.
9881
9880
const clang::Module *declSubmodule = *getClangSubmoduleForDecl (decl);
9882
9881
auto extensionKey = std::make_pair (nominal, declSubmodule);
9883
- auto knownExtension = extensionPoints.find (extensionKey);
9884
- if (knownExtension != extensionPoints. end () )
9885
- return knownExtension-> second ;
9882
+ auto [it, inserted] = extensionPoints.try_emplace (extensionKey, nullptr );
9883
+ if (!inserted )
9884
+ return it-> getSecond () ;
9886
9885
9887
9886
// Create a new extension for this nominal type/Clang submodule pair.
9888
9887
auto ext = ExtensionDecl::create (SwiftContext, SourceLoc (), nullptr , {},
@@ -9895,7 +9894,7 @@ ClangImporter::Implementation::importDeclContextOf(
9895
9894
// Record this extension so we can find it later. We do this early because
9896
9895
// once we've set the member loader, we don't know when the compiler will use
9897
9896
// it and end up back in this method.
9898
- extensionPoints[extensionKey] = ext;
9897
+ it-> getSecond () = ext;
9899
9898
ext->setMemberLoader (this , reinterpret_cast <uintptr_t >(declSubmodule));
9900
9899
9901
9900
if (auto protoDecl = ext->getExtendedProtocolDecl ()) {
0 commit comments