Skip to content

Commit

Permalink
[Attributes] Avoid duplicate hasAttribute() query (NFC)
Browse files Browse the repository at this point in the history
removeAttribute() already performs a hasAttribute() check, so no
need to also do it in the caller. Instead check whether the
attribute set was changed.

This makes the implementations in line with removeAttributesAtIndex().
  • Loading branch information
nikic committed Jan 9, 2023
1 parent 07d6af6 commit 9afb636
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions llvm/lib/IR/Attributes.cpp
Expand Up @@ -1380,18 +1380,20 @@ AttributeList
AttributeList::removeAttributeAtIndex(LLVMContext &C, unsigned Index,
Attribute::AttrKind Kind) const {
AttributeSet Attrs = getAttributes(Index);
if (!Attrs.hasAttribute(Kind))
AttributeSet NewAttrs = Attrs.removeAttribute(C, Kind);
if (Attrs == NewAttrs)
return *this;
return setAttributesAtIndex(C, Index, Attrs.removeAttribute(C, Kind));
return setAttributesAtIndex(C, Index, NewAttrs);
}

AttributeList AttributeList::removeAttributeAtIndex(LLVMContext &C,
unsigned Index,
StringRef Kind) const {
AttributeSet Attrs = getAttributes(Index);
if (!Attrs.hasAttribute(Kind))
AttributeSet NewAttrs = Attrs.removeAttribute(C, Kind);
if (Attrs == NewAttrs)
return *this;
return setAttributesAtIndex(C, Index, Attrs.removeAttribute(C, Kind));
return setAttributesAtIndex(C, Index, NewAttrs);
}

AttributeList AttributeList::removeAttributesAtIndex(
Expand Down

0 comments on commit 9afb636

Please sign in to comment.