Skip to content

Commit b24909c

Browse files
committed
[Attributes] Avoid repeated attribute set lookup (NFC)
Perform the hasAttribute() check on the AttributeSet we need to fetch anyway, rather than going through hasAttributeAtIndex().
1 parent e6375ca commit b24909c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

llvm/lib/IR/Attributes.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,9 +1301,9 @@ AttributeList AttributeList::get(LLVMContext &C,
13011301
AttributeList
13021302
AttributeList::addAttributeAtIndex(LLVMContext &C, unsigned Index,
13031303
Attribute::AttrKind Kind) const {
1304-
if (hasAttributeAtIndex(Index, Kind))
1305-
return *this;
13061304
AttributeSet Attrs = getAttributes(Index);
1305+
if (Attrs.hasAttribute(Kind))
1306+
return *this;
13071307
// TODO: Insert at correct position and avoid sort.
13081308
SmallVector<Attribute, 8> NewAttrs(Attrs.begin(), Attrs.end());
13091309
NewAttrs.push_back(Attribute::get(C, Kind));
@@ -1379,19 +1379,19 @@ AttributeList AttributeList::addParamAttribute(LLVMContext &C,
13791379
AttributeList
13801380
AttributeList::removeAttributeAtIndex(LLVMContext &C, unsigned Index,
13811381
Attribute::AttrKind Kind) const {
1382-
if (!hasAttributeAtIndex(Index, Kind))
1382+
AttributeSet Attrs = getAttributes(Index);
1383+
if (!Attrs.hasAttribute(Kind))
13831384
return *this;
1384-
return setAttributesAtIndex(C, Index,
1385-
getAttributes(Index).removeAttribute(C, Kind));
1385+
return setAttributesAtIndex(C, Index, Attrs.removeAttribute(C, Kind));
13861386
}
13871387

13881388
AttributeList AttributeList::removeAttributeAtIndex(LLVMContext &C,
13891389
unsigned Index,
13901390
StringRef Kind) const {
1391-
if (!hasAttributeAtIndex(Index, Kind))
1391+
AttributeSet Attrs = getAttributes(Index);
1392+
if (!Attrs.hasAttribute(Kind))
13921393
return *this;
1393-
return setAttributesAtIndex(C, Index,
1394-
getAttributes(Index).removeAttribute(C, Kind));
1394+
return setAttributesAtIndex(C, Index, Attrs.removeAttribute(C, Kind));
13951395
}
13961396

13971397
AttributeList AttributeList::removeAttributesAtIndex(

0 commit comments

Comments
 (0)