From: Craig Topper Date: Thu, 22 Oct 2015 01:56:18 +0000 (+0000) Subject: Change SortAndUniqueProtocols to operate directly on a SmallVector rather than taking... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e1b9cff5dc1a0dbec499e9718ebe54c1f4e86c1;p=clang Change SortAndUniqueProtocols to operate directly on a SmallVector rather than taking a pointer and element count that it modifies. This paves the way to directly convert the small vector into an ArrayRef without needing to explicitly pass the modified size. No functional change intended. While there also use a range-based for loop and use append instead of insert to copy elements into the empty SmallVector." git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250971 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 848158877a..dd47d43ccb 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -3638,20 +3638,18 @@ static bool areSortedAndUniqued(ObjCProtocolDecl * const *Protocols, return true; } -static void SortAndUniqueProtocols(ObjCProtocolDecl **Protocols, - unsigned &NumProtocols) { - ObjCProtocolDecl **ProtocolsEnd = Protocols+NumProtocols; - +static void +SortAndUniqueProtocols(SmallVectorImpl &Protocols) { // Sort protocols, keyed by name. - llvm::array_pod_sort(Protocols, ProtocolsEnd, CmpProtocolNames); + llvm::array_pod_sort(Protocols.begin(), Protocols.end(), CmpProtocolNames); // Canonicalize. - for (unsigned I = 0, N = NumProtocols; I != N; ++I) - Protocols[I] = Protocols[I]->getCanonicalDecl(); - + for (ObjCProtocolDecl *&P : Protocols) + P = P->getCanonicalDecl(); + // Remove duplicates. - ProtocolsEnd = std::unique(Protocols, ProtocolsEnd); - NumProtocols = ProtocolsEnd-Protocols; + auto ProtocolsEnd = std::unique(Protocols.begin(), Protocols.end()); + Protocols.erase(ProtocolsEnd, Protocols.end()); } QualType ASTContext::getObjCObjectType(QualType BaseType, @@ -3716,12 +3714,9 @@ QualType ASTContext::getObjCObjectType( ArrayRef canonProtocols; SmallVector canonProtocolsVec; if (!protocolsSorted) { - canonProtocolsVec.insert(canonProtocolsVec.begin(), - protocols.begin(), - protocols.end()); - unsigned uniqueCount = protocols.size(); - SortAndUniqueProtocols(&canonProtocolsVec[0], uniqueCount); - canonProtocols = llvm::makeArrayRef(&canonProtocolsVec[0], uniqueCount); + canonProtocolsVec.append(protocols.begin(), protocols.end()); + SortAndUniqueProtocols(canonProtocolsVec); + canonProtocols = canonProtocolsVec; } else { canonProtocols = protocols; }