From 8d6385db78faf87bea65792619a6a5ca10545d84 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sat, 17 Oct 2015 16:37:11 +0000 Subject: [PATCH] Use std::begin/end and std::is_sorted to simplify some code. NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250614 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCSubtargetInfo.cpp | 13 ++++++------- lib/Target/ARM/ARMExpandPseudoInsts.cpp | 13 +++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/MC/MCSubtargetInfo.cpp b/lib/MC/MCSubtargetInfo.cpp index 9210cf544b1..f3fff72c3c9 100644 --- a/lib/MC/MCSubtargetInfo.cpp +++ b/lib/MC/MCSubtargetInfo.cpp @@ -77,13 +77,12 @@ FeatureBitset MCSubtargetInfo::ApplyFeatureFlag(StringRef FS) { const MCSchedModel &MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const { assert(ProcSchedModels && "Processor machine model not available!"); - unsigned NumProcs = ProcDesc.size(); -#ifndef NDEBUG - for (size_t i = 1; i < NumProcs; i++) { - assert(strcmp(ProcSchedModels[i - 1].Key, ProcSchedModels[i].Key) < 0 && - "Processor machine model table is not sorted"); - } -#endif + size_t NumProcs = ProcDesc.size(); + assert(std::is_sorted(ProcSchedModels, ProcSchedModels+NumProcs, + [](const SubtargetInfoKV &LHS, const SubtargetInfoKV &RHS) { + return strcmp(LHS.Key, RHS.Key) < 0; + }) && + "Processor machine model table is not sorted"); // Find entry const SubtargetInfoKV *Found = diff --git a/lib/Target/ARM/ARMExpandPseudoInsts.cpp b/lib/Target/ARM/ARMExpandPseudoInsts.cpp index f090e5abd95..745fd3fcdf1 100644 --- a/lib/Target/ARM/ARMExpandPseudoInsts.cpp +++ b/lib/Target/ARM/ARMExpandPseudoInsts.cpp @@ -330,22 +330,19 @@ static const NEONLdStTableEntry NEONLdStTable[] = { /// LookupNEONLdSt - Search the NEONLdStTable for information about a NEON /// load or store pseudo instruction. static const NEONLdStTableEntry *LookupNEONLdSt(unsigned Opcode) { - const unsigned NumEntries = array_lengthof(NEONLdStTable); - #ifndef NDEBUG // Make sure the table is sorted. static bool TableChecked = false; if (!TableChecked) { - for (unsigned i = 0; i != NumEntries-1; ++i) - assert(NEONLdStTable[i] < NEONLdStTable[i+1] && - "NEONLdStTable is not sorted!"); + assert(std::is_sorted(std::begin(NEONLdStTable), std::end(NEONLdStTable)) && + "NEONLdStTable is not sorted!"); TableChecked = true; } #endif - const NEONLdStTableEntry *I = - std::lower_bound(NEONLdStTable, NEONLdStTable + NumEntries, Opcode); - if (I != NEONLdStTable + NumEntries && I->PseudoOpc == Opcode) + const auto I = std::lower_bound(std::begin(NEONLdStTable), + std::end(NEONLdStTable), Opcode); + if (I != std::end(NEONLdStTable) && I->PseudoOpc == Opcode) return I; return nullptr; } -- 2.34.1