Skip to content

Commit e66be7a

Browse files
gregomnijckarter
authored andcommitted
Use an oh-so-fancy MapVector.
1 parent 01ce96c commit e66be7a

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

lib/SIL/TypeLowering.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,8 +2063,7 @@ TypeConverter::getLoweredLocalCaptures(AnyFunctionRef fn) {
20632063

20642064
// Recursively collect transitive captures from captured local functions.
20652065
llvm::DenseSet<AnyFunctionRef> visitedFunctions;
2066-
llvm::DenseSet<ValueDecl*> capturedValues;
2067-
llvm::SmallVector<CapturedValue, 4> captures;
2066+
llvm::MapVector<ValueDecl*,CapturedValue> captures;
20682067

20692068
// If there is a capture of 'self' with dynamic 'Self' type, it goes last so
20702069
// that IRGen can pass dynamic 'Self' metadata.
@@ -2170,29 +2169,29 @@ TypeConverter::getLoweredLocalCaptures(AnyFunctionRef fn) {
21702169
capture_value:
21712170
// Collect non-function captures.
21722171
ValueDecl *value = capture.getDecl();
2173-
if (capturedValues.count(value)) {
2174-
for (auto it = captures.begin(); it != captures.end(); ++it) {
2175-
if (it->getDecl() == value) {
2176-
*it = it->mergeFlags(capture);
2177-
break;
2178-
}
2179-
}
2172+
auto existing = captures.find(value);
2173+
if (existing != captures.end()) {
2174+
existing->second = existing->second.mergeFlags(capture);
21802175
} else {
2181-
capturedValues.insert(value);
2182-
captures.push_back(capture);
2176+
captures.insert(std::pair<ValueDecl *, CapturedValue>(value, capture));
21832177
}
21842178
}
21852179
};
21862180
collectFunctionCaptures(fn);
21872181

2182+
SmallVector<CapturedValue, 4> resultingCaptures;
2183+
for (auto capturePair : captures) {
2184+
resultingCaptures.push_back(capturePair.second);
2185+
}
2186+
21882187
// If we captured the dynamic 'Self' type and we have a 'self' value also,
21892188
// add it as the final capture. Otherwise, add a fake hidden capture for
21902189
// the dynamic 'Self' metatype.
21912190
if (selfCapture.hasValue()) {
2192-
captures.push_back(*selfCapture);
2191+
resultingCaptures.push_back(*selfCapture);
21932192
} else if (capturesDynamicSelf) {
21942193
selfCapture = CapturedValue::getDynamicSelfMetadata();
2195-
captures.push_back(*selfCapture);
2194+
resultingCaptures.push_back(*selfCapture);
21962195
}
21972196

21982197
// Cache the uniqued set of transitive captures.
@@ -2201,7 +2200,7 @@ TypeConverter::getLoweredLocalCaptures(AnyFunctionRef fn) {
22012200
auto &cachedCaptures = inserted.first->second;
22022201
cachedCaptures.setGenericParamCaptures(capturesGenericParams);
22032202
cachedCaptures.setDynamicSelfType(capturesDynamicSelf);
2204-
cachedCaptures.setCaptures(Context.AllocateCopy(captures));
2203+
cachedCaptures.setCaptures(Context.AllocateCopy(resultingCaptures));
22052204

22062205
return cachedCaptures;
22072206
}

0 commit comments

Comments
 (0)