Author: ctopper Date: Wed Oct 21 20:56:18 2015 New Revision: 250971 URL: http://llvm.org/viewvc/llvm-project?rev=250971&view=rev Log: 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." Modified: cfe/trunk/lib/AST/ASTContext.cpp Modified: cfe/trunk/lib/AST/ASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=250971&r1=250970&r2=250971&view=diff ============================================================================== --- cfe/trunk/lib/AST/ASTContext.cpp (original) +++ cfe/trunk/lib/AST/ASTContext.cpp Wed Oct 21 20:56:18 2015 @@ -3638,20 +3638,18 @@ static bool areSortedAndUniqued(ObjCProt return true; } -static void SortAndUniqueProtocols(ObjCProtocolDecl **Protocols, - unsigned &NumProtocols) { - ObjCProtocolDecl **ProtocolsEnd = Protocols+NumProtocols; - +static void +SortAndUniqueProtocols(SmallVectorImpl<ObjCProtocolDecl *> &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<ObjCProtocolDecl *> canonProtocols; SmallVector<ObjCProtocolDecl*, 8> 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; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits