[llvm] r250614 - Use std::begin/end and std::is_sorted to simplify some code. NFC
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 17 10:20:06 PDT 2015
On Sat, Oct 17, 2015 at 9:37 AM, Craig Topper via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: ctopper
> Date: Sat Oct 17 11:37:11 2015
> New Revision: 250614
>
> URL: http://llvm.org/viewvc/llvm-project?rev=250614&view=rev
> Log:
> Use std::begin/end and std::is_sorted to simplify some code. NFC
>
> Modified:
> llvm/trunk/lib/MC/MCSubtargetInfo.cpp
> llvm/trunk/lib/Target/ARM/ARMExpandPseudoInsts.cpp
>
> Modified: llvm/trunk/lib/MC/MCSubtargetInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCSubtargetInfo.cpp?rev=250614&r1=250613&r2=250614&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/MC/MCSubtargetInfo.cpp (original)
> +++ llvm/trunk/lib/MC/MCSubtargetInfo.cpp Sat Oct 17 11:37:11 2015
> @@ -77,13 +77,12 @@ FeatureBitset MCSubtargetInfo::ApplyFeat
> 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 =
>
> Modified: llvm/trunk/lib/Target/ARM/ARMExpandPseudoInsts.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMExpandPseudoInsts.cpp?rev=250614&r1=250613&r2=250614&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM/ARMExpandPseudoInsts.cpp (original)
> +++ llvm/trunk/lib/Target/ARM/ARMExpandPseudoInsts.cpp Sat Oct 17 11:37:11
> 2015
> @@ -330,22 +330,19 @@ static const NEONLdStTableEntry NEONLdSt
> /// 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),
>
The 'const' seems a bit unnecessary here (we don't usually use top level
const on locals) - you could add the '*' back in, but it makes sense to me
to treat it like an opaque iterator, rather than being explicit about the
fact that it's a real pointer, so I'd be happy with just "auto I".
> + std::end(NEONLdStTable), Opcode);
> + if (I != std::end(NEONLdStTable) && I->PseudoOpc == Opcode)
> return I;
> return nullptr;
> }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151017/8e78b8f6/attachment.html>
More information about the llvm-commits
mailing list