Skip to content

[NFC] AST: Optimize GenericSignatureImpl::getInnermostGenericParams #31838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions lib/AST/GenericSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,22 @@ GenericSignatureImpl::GenericSignatureImpl(

TypeArrayView<GenericTypeParamType>
GenericSignatureImpl::getInnermostGenericParams() const {
auto params = getGenericParams();
const auto params = getGenericParams();

// Find the point at which the depth changes.
unsigned depth = params.back()->getDepth();
for (unsigned n = params.size(); n > 0; --n) {
if (params[n-1]->getDepth() != depth) {
return params.slice(n);
}
const unsigned maxDepth = params.back()->getDepth();
if (params.front()->getDepth() == maxDepth)
return params;

// There is a depth change. Count the number of elements
// to slice off the front.
unsigned sliceCount = params.size() - 1;
while (true) {
if (params[sliceCount - 1]->getDepth() != maxDepth)
break;
--sliceCount;
}

// All parameters are at the same depth.
return params;
return params.slice(sliceCount);
}

void GenericSignatureImpl::forEachParam(
Expand Down