Metadata: Use <algorithm> to simplify code. NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228550 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2015-02-08 21:56:09 +00:00
parent 4616d7dd2f
commit 15307c3eb2

View File

@ -84,8 +84,7 @@ MetadataAsValue *MetadataAsValue::getIfExists(LLVMContext &Context,
Metadata *MD) { Metadata *MD) {
MD = canonicalizeMetadataForValue(Context, MD); MD = canonicalizeMetadataForValue(Context, MD);
auto &Store = Context.pImpl->MetadataAsValues; auto &Store = Context.pImpl->MetadataAsValues;
auto I = Store.find(MD); return Store.lookup(MD);
return I == Store.end() ? nullptr : I->second;
} }
void MetadataAsValue::handleChangedMetadata(Metadata *MD) { void MetadataAsValue::handleChangedMetadata(Metadata *MD) {
@ -439,8 +438,7 @@ static bool isOperandUnresolved(Metadata *Op) {
unsigned MDNode::countUnresolvedOperands() { unsigned MDNode::countUnresolvedOperands() {
assert(NumUnresolved == 0 && "Expected unresolved ops to be uncounted"); assert(NumUnresolved == 0 && "Expected unresolved ops to be uncounted");
for (const auto &Op : operands()) NumUnresolved = std::count_if(op_begin(), op_end(), isOperandUnresolved);
NumUnresolved += unsigned(isOperandUnresolved(Op));
return NumUnresolved; return NumUnresolved;
} }
@ -750,13 +748,10 @@ MDNode *MDNode::concatenate(MDNode *A, MDNode *B) {
if (!B) if (!B)
return A; return A;
SmallVector<Metadata *, 4> MDs(A->getNumOperands() + B->getNumOperands()); SmallVector<Metadata *, 4> MDs;
MDs.reserve(A->getNumOperands() + B->getNumOperands());
unsigned j = 0; MDs.append(A->op_begin(), A->op_end());
for (unsigned i = 0, ie = A->getNumOperands(); i != ie; ++i) MDs.append(B->op_begin(), B->op_end());
MDs[j++] = A->getOperand(i);
for (unsigned i = 0, ie = B->getNumOperands(); i != ie; ++i)
MDs[j++] = B->getOperand(i);
// FIXME: This preserves long-standing behaviour, but is it really the right // FIXME: This preserves long-standing behaviour, but is it really the right
// behaviour? Or was that an unintended side-effect of node uniquing? // behaviour? Or was that an unintended side-effect of node uniquing?
@ -768,14 +763,9 @@ MDNode *MDNode::intersect(MDNode *A, MDNode *B) {
return nullptr; return nullptr;
SmallVector<Metadata *, 4> MDs; SmallVector<Metadata *, 4> MDs;
for (unsigned i = 0, ie = A->getNumOperands(); i != ie; ++i) { for (Metadata *MD : A->operands())
Metadata *MD = A->getOperand(i); if (std::find(B->op_begin(), B->op_end(), MD) != B->op_end())
for (unsigned j = 0, je = B->getNumOperands(); j != je; ++j) MDs.push_back(MD);
if (MD == B->getOperand(j)) {
MDs.push_back(MD);
break;
}
}
// FIXME: This preserves long-standing behaviour, but is it really the right // FIXME: This preserves long-standing behaviour, but is it really the right
// behaviour? Or was that an unintended side-effect of node uniquing? // behaviour? Or was that an unintended side-effect of node uniquing?
@ -787,17 +777,9 @@ MDNode *MDNode::getMostGenericAliasScope(MDNode *A, MDNode *B) {
return nullptr; return nullptr;
SmallVector<Metadata *, 4> MDs(B->op_begin(), B->op_end()); SmallVector<Metadata *, 4> MDs(B->op_begin(), B->op_end());
for (unsigned i = 0, ie = A->getNumOperands(); i != ie; ++i) { for (Metadata *MD : A->operands())
Metadata *MD = A->getOperand(i); if (std::find(B->op_begin(), B->op_end(), MD) == B->op_end())
bool insert = true; MDs.push_back(MD);
for (unsigned j = 0, je = B->getNumOperands(); j != je; ++j)
if (MD == B->getOperand(j)) {
insert = false;
break;
}
if (insert)
MDs.push_back(MD);
}
// FIXME: This preserves long-standing behaviour, but is it really the right // FIXME: This preserves long-standing behaviour, but is it really the right
// behaviour? Or was that an unintended side-effect of node uniquing? // behaviour? Or was that an unintended side-effect of node uniquing?