From 8b3e1adf2b4a69b6055dc4e07b4e97817208c904 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Thu, 11 Nov 2021 18:20:52 -0800 Subject: [PATCH] IR: Avoid duplication of SwitchInst::findCaseValue(), NFC Change the non-const version of findCaseValue() to forward to the const version. --- llvm/include/llvm/IR/Instructions.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h index 0ef78881c6d7a..45984d2d0a727 100644 --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -3515,12 +3515,9 @@ class SwitchInst : public Instruction { /// default case iterator to indicate that it is handled by the default /// handler. CaseIt findCaseValue(const ConstantInt *C) { - CaseIt I = llvm::find_if( - cases(), [C](CaseHandle &Case) { return Case.getCaseValue() == C; }); - if (I != case_end()) - return I; - - return case_default(); + return CaseIt( + this, + const_cast(this)->findCaseValue(C)->getCaseIndex()); } ConstCaseIt findCaseValue(const ConstantInt *C) const { ConstCaseIt I = llvm::find_if(cases(), [C](ConstCaseHandle &Case) {