diff options
author | Anders Carlsson <andersca@mac.com> | 2007-12-19 06:16:30 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2007-12-19 06:16:30 +0000 |
commit | 6ede0ffdb2dc3ca7b57ec1075676f5a8fed0dc3b (patch) | |
tree | 190a30ab5b4a80e67c57e918f381a96f446ecbad | |
parent | 54b263b0d499b758d57cb3e08fae34ed768842b5 (diff) |
Normalize attribute names if possible so we won't have to do two strcmps for every attribute.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45191 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | Sema/SemaDecl.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index cf52817cb9..12f7d7a388 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -1650,8 +1650,17 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX, } void Sema::HandleDeclAttribute(Decl *New, AttributeList *rawAttr) { - if (!strcmp(rawAttr->getAttributeName()->getName(), "vector_size") || - !strcmp(rawAttr->getAttributeName()->getName(), "__vector_size__")) { + const char *attrName = rawAttr->getAttributeName()->getName(); + unsigned attrLen = rawAttr->getAttributeName()->getLength(); + + // Normalize the attribute name, __foo__ becomes foo. + if (attrLen > 4 && attrName[0] == '_' && attrName[1] == '_' && + attrName[attrLen - 2] == '_' && attrName[attrLen - 1] == '-') { + attrName += 2; + attrLen -= 4; + } + + if (attrLen == 11 && !memcmp(attrName, "vector_size", 11)) { if (ValueDecl *vDecl = dyn_cast<ValueDecl>(New)) { QualType newType = HandleVectorTypeAttribute(vDecl->getType(), rawAttr); if (!newType.isNull()) // install the new vector type into the decl @@ -1663,9 +1672,7 @@ void Sema::HandleDeclAttribute(Decl *New, AttributeList *rawAttr) { if (!newType.isNull()) // install the new vector type into the decl tDecl->setUnderlyingType(newType); } - } - if (!strcmp(rawAttr->getAttributeName()->getName(), "ocu_vector_type") || - !strcmp(rawAttr->getAttributeName()->getName(), "__ocu_vector_type__")) { + } else if (attrLen == 15 && !memcmp(attrName, "ocu_vector_type", 15)) { if (TypedefDecl *tDecl = dyn_cast<TypedefDecl>(New)) HandleOCUVectorTypeAttribute(tDecl, rawAttr); else |