Skip to content

Commit 9357c85

Browse files
authored
Merge pull request #31838 from AnthonyLatsis/o-getinnermostgps
[NFC] AST: Optimize GenericSignatureImpl::getInnermostGenericParams
2 parents 5e1eadc + 95c16fc commit 9357c85

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/AST/GenericSignature.cpp

+13-9
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,22 @@ GenericSignatureImpl::GenericSignatureImpl(
7676

7777
TypeArrayView<GenericTypeParamType>
7878
GenericSignatureImpl::getInnermostGenericParams() const {
79-
auto params = getGenericParams();
79+
const auto params = getGenericParams();
8080

81-
// Find the point at which the depth changes.
82-
unsigned depth = params.back()->getDepth();
83-
for (unsigned n = params.size(); n > 0; --n) {
84-
if (params[n-1]->getDepth() != depth) {
85-
return params.slice(n);
86-
}
81+
const unsigned maxDepth = params.back()->getDepth();
82+
if (params.front()->getDepth() == maxDepth)
83+
return params;
84+
85+
// There is a depth change. Count the number of elements
86+
// to slice off the front.
87+
unsigned sliceCount = params.size() - 1;
88+
while (true) {
89+
if (params[sliceCount - 1]->getDepth() != maxDepth)
90+
break;
91+
--sliceCount;
8792
}
8893

89-
// All parameters are at the same depth.
90-
return params;
94+
return params.slice(sliceCount);
9195
}
9296

9397
void GenericSignatureImpl::forEachParam(

0 commit comments

Comments
 (0)