Skip to content

Commit f41deb0

Browse files
Merge pull request #61588 from LucianoPAlmeida/nfc-optional
[NFC][AST] Change TypeBase::getOptionalityDepth() implementation to not use a vector
2 parents 3c2c7f6 + 1e6bdf7 commit f41deb0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/AST/Type.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,9 +884,13 @@ Type TypeBase::lookThroughAllOptionalTypes(SmallVectorImpl<Type> &optionals){
884884
}
885885

886886
unsigned int TypeBase::getOptionalityDepth() {
887-
SmallVector<Type> types;
888-
lookThroughAllOptionalTypes(types);
889-
return types.size();
887+
Type type(this);
888+
unsigned int depth = 0;
889+
while (auto objType = type->getOptionalObjectType()) {
890+
type = objType;
891+
++depth;
892+
}
893+
return depth;
890894
}
891895

892896
Type TypeBase::stripConcurrency(bool recurse, bool dropGlobalActor) {

0 commit comments

Comments
 (0)