Skip to content

Commit 2e3197e

Browse files
committed
Simplify some code. No change in functionality.
llvm-svn: 102445
1 parent 4423926 commit 2e3197e

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,10 +2119,10 @@ QualType ASTContext::getObjCObjectPointerType(QualType InterfaceT,
21192119
if (!InterfaceT.isCanonical() ||
21202120
!areSortedAndUniqued(Protocols, NumProtocols)) {
21212121
if (!areSortedAndUniqued(Protocols, NumProtocols)) {
2122-
llvm::SmallVector<ObjCProtocolDecl*, 8> Sorted(NumProtocols);
2122+
llvm::SmallVector<ObjCProtocolDecl*, 8> Sorted(Protocols,
2123+
Protocols + NumProtocols);
21232124
unsigned UniqueCount = NumProtocols;
21242125

2125-
std::copy(Protocols, Protocols + NumProtocols, Sorted.begin());
21262126
SortAndUniqueProtocols(&Sorted[0], UniqueCount);
21272127

21282128
Canonical = getObjCObjectPointerType(getCanonicalType(InterfaceT),
@@ -2165,8 +2165,8 @@ QualType ASTContext::getObjCInterfaceType(const ObjCInterfaceDecl *Decl,
21652165
// Sort the protocol list alphabetically to canonicalize it.
21662166
QualType Canonical;
21672167
if (NumProtocols && !areSortedAndUniqued(Protocols, NumProtocols)) {
2168-
llvm::SmallVector<ObjCProtocolDecl*, 8> Sorted(NumProtocols);
2169-
std::copy(Protocols, Protocols + NumProtocols, Sorted.begin());
2168+
llvm::SmallVector<ObjCProtocolDecl*, 8> Sorted(Protocols,
2169+
Protocols + NumProtocols);
21702170

21712171
unsigned UniqueCount = NumProtocols;
21722172
SortAndUniqueProtocols(&Sorted[0], UniqueCount);
@@ -2645,14 +2645,9 @@ QualType ASTContext::getArrayDecayedType(QualType Ty) {
26452645

26462646
QualType ASTContext::getBaseElementType(QualType QT) {
26472647
QualifierCollector Qs;
2648-
while (true) {
2649-
const Type *UT = Qs.strip(QT);
2650-
if (const ArrayType *AT = getAsArrayType(QualType(UT,0))) {
2651-
QT = AT->getElementType();
2652-
} else {
2653-
return Qs.apply(QT);
2654-
}
2655-
}
2648+
while (const ArrayType *AT = getAsArrayType(QualType(Qs.strip(QT), 0)))
2649+
QT = AT->getElementType();
2650+
return Qs.apply(QT);
26562651
}
26572652

26582653
QualType ASTContext::getBaseElementType(const ArrayType *AT) {
@@ -3579,12 +3574,8 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S,
35793574
// Another legacy compatibility encoding. Some ObjC qualifier and type
35803575
// combinations need to be rearranged.
35813576
// Rewrite "in const" from "nr" to "rn"
3582-
const char * s = S.c_str();
3583-
int len = S.length();
3584-
if (len >= 2 && s[len-2] == 'n' && s[len-1] == 'r') {
3585-
std::string replace = "rn";
3586-
S.replace(S.end()-2, S.end(), replace);
3587-
}
3577+
if (llvm::StringRef(S).endswith("nr"))
3578+
S.replace(S.end()-2, S.end(), "rn");
35883579
}
35893580

35903581
if (PointeeTy->isCharType()) {

0 commit comments

Comments
 (0)