Skip to content

Commit 83586c7

Browse files
committed
[Serialization] Move helper lambda into DeclDeserializer
And cache the ASTContext pointer for convenience.
1 parent 9f80d71 commit 83586c7

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,6 +2234,7 @@ class swift::DeclDeserializer {
22342234
using TypeID = serialization::TypeID;
22352235

22362236
ModuleFile &MF;
2237+
ASTContext &ctx;
22372238
Serialized<Decl *> &declOrOffset;
22382239

22392240
DeclAttribute *DAttrs = nullptr;
@@ -2252,9 +2253,18 @@ class swift::DeclDeserializer {
22522253
AttrsNext = Attr->getMutableNext();
22532254
};
22542255

2256+
void handleInherited(TypeDecl *nominal, ArrayRef<uint64_t> rawInheritedIDs) {
2257+
auto inheritedTypes = ctx.Allocate<TypeLoc>(rawInheritedIDs.size());
2258+
for_each(inheritedTypes, rawInheritedIDs,
2259+
[this](TypeLoc &tl, uint64_t rawID) {
2260+
tl = TypeLoc::withoutLoc(MF.getType(rawID));
2261+
});
2262+
nominal->setInherited(inheritedTypes);
2263+
}
2264+
22552265
public:
22562266
DeclDeserializer(ModuleFile &MF, Serialized<Decl *> &declOrOffset)
2257-
: MF(MF), declOrOffset(declOrOffset) {}
2267+
: MF(MF), ctx(MF.getContext()), declOrOffset(declOrOffset) {}
22582268

22592269
~DeclDeserializer() {
22602270
if (!declOrOffset.isComplete()) {
@@ -2377,7 +2387,6 @@ static bool attributeChainContains(DeclAttribute *attr) {
23772387
llvm::Error DeclDeserializer::deserializeDeclAttributes() {
23782388
using namespace decls_block;
23792389

2380-
ASTContext &ctx = MF.getContext();
23812390
SmallVector<uint64_t, 64> scratch;
23822391
StringRef blobData;
23832392
while (true) {
@@ -2668,22 +2677,9 @@ DeclDeserializer::getDeclCheckedImpl(ModuleFile &MF, DeclID DID) {
26682677

26692678
Expected<Decl *>
26702679
DeclDeserializer::getDeclCheckedImpl() {
2671-
ASTContext &ctx = MF.getContext();
2672-
26732680
if (auto s = ctx.Stats)
26742681
s->getFrontendCounters().NumDeclsDeserialized++;
26752682

2676-
// Local function that handles the "inherited" list for a type.
2677-
auto handleInherited
2678-
= [&](TypeDecl *nominal, ArrayRef<uint64_t> rawInheritedIDs) {
2679-
auto inheritedTypes = ctx.Allocate<TypeLoc>(rawInheritedIDs.size());
2680-
for_each(inheritedTypes, rawInheritedIDs,
2681-
[this](TypeLoc &tl, uint64_t rawID) {
2682-
tl = TypeLoc::withoutLoc(MF.getType(rawID));
2683-
});
2684-
nominal->setInherited(inheritedTypes);
2685-
};
2686-
26872683
auto attrError = deserializeDeclAttributes();
26882684
if (attrError)
26892685
return std::move(attrError);

0 commit comments

Comments
 (0)